Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 6.1.x rails new; rake assets:precompile is broken #48372

Closed
schneems opened this issue Jun 1, 2023 · 12 comments
Closed

Rails 6.1.x rails new; rake assets:precompile is broken #48372

schneems opened this issue Jun 1, 2023 · 12 comments
Labels

Comments

@schneems
Copy link
Member

schneems commented Jun 1, 2023

Steps to reproduce

mkdir -p /tmp/79de2b03fd57b181232892d89e7e9920; cd /tmp/79de2b03fd57b181232892d89e7e9920
rails _6.1.7.3_ new myapp --database=postgresql
cd myapp
RAILS_ENV=production SECRET_KEY_BASE=asdf bundle exec rake assets:precompile assets:clean

Expected behavior

It precompiles fine

Actual behavior

Compiling...
Compilation failed:
node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: Cannot find package '@babel/plugin-proposal-private-methods' imported from /private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/babel-virtual-resolve-base.js
    at new NodeError (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:203:5)
    at packageResolve (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:873:9)
    at moduleResolve (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:902:20)
    at defaultResolve (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:985:15)
    at resolve (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:999:12)
    at resolve (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/config/files/import-meta-resolve.js:13:10)
    at tryImportMetaResolve (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/config/files/plugins.js:123:45)
    at resolveStandardizedNameForImport (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/config/files/plugins.js:145:19)
    at resolveStandardizedName (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/config/files/plugins.js:154:12)
    at loadPlugin (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/config/files/plugins.js:47:20)
    at loadPlugin.next (<anonymous>)
    at createDescriptor (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/config/config-descriptors.js:139:16)
    at createDescriptor.next (<anonymous>)
    at step (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/gensync/index.js:261:32)
    at evaluateAsync (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/gensync/index.js:291:5)
    at /private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/gensync/index.js:44:11
    at Array.forEach (<anonymous>)
    at Function.async (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/gensync/index.js:43:15)
    at Function.all (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/gensync/index.js:216:13)
    at Generator.next (<anonymous>)
    at createDescriptors (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/config/config-descriptors.js:101:41)
    at createDescriptors.next (<anonymous>)
    at createPluginDescriptors (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/config/config-descriptors.js:98:17)
    at createPluginDescriptors.next (<anonymous>)
    at /private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/gensync-utils/functional.js:21:23
    at Generator.next (<anonymous>)
    at mergeChainOpts (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/config/config-chain.js:349:34)
    at mergeChainOpts.next (<anonymous>)
    at chainWalker (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/config/config-chain.js:316:14)
    at chainWalker.next (<anonymous>)
    at loadFileChain (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/config/config-chain.js:192:24)
    at loadFileChain.next (<anonymous>)
    at buildRootChain (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/config/config-chain.js:78:27)
    at buildRootChain.next (<anonymous>)
    at loadPrivatePartialConfig (/private/tmp/79de2b03fd57b181232892d89e7e9920/myapp/node_modules/@babel/core/lib/config/partial.js:79:62)
    at loadPrivatePartialConfig.next (<anonymous>) {
  code: 'ERR_MODULE_NOT_FOUND'
}

System configuration

Rails version: 6.1.7.3

Ruby version: 3.0.6

Notes

This appears to be happening because webpacker generates a babel.config.js https://github.com/rails/webpacker/blob/1cec8408d9c30e458c9f83b0c50ef53a255a4352/lib/install/config/babel.config.js#L57-L60 that includes plugin-proposal-private-methods, however it does not add a dependency to plugin-proposal-private-methods. Instead, it depends on a package that depends on plugin-proposal-private-methods.

Recently that package was re-named to plugin-transform-private-methods babel/babel#15614 and I believe it was released babel/babel@389ecb0.

So now when babel tries to execute it reads in the babel.config.js file, sees that it needs plugin-proposal-private-methods. Tries to load it, but that fails because plugin-proposal-private-methods is not installed (since it is no longer a dependency).

A suggested path forward: Update the babel.config.js to reference the new file name. Or explicitly depend on all plugins in the babel.config.js. Maybe lock down some dependency versions.

To anyone hitting this error in your app you can change the name in your babel.config.js like this:

-       '@babel/plugin-proposal-private-methods',
+       '@babel/plugin-transform-private-methods', 

There are more "proposal" items in there. As this happens again, people will hit the same bug.

@skipkayhil
Copy link
Member

Looks like there was a PR opened to fix this in Webpacker, but neither Rails 6 nor Webpacker are receiving bug fixes: rails/webpacker#3315 (comment)

@schneems
Copy link
Member Author

schneems commented Jun 2, 2023

I know about the support policy, also there’s some amount of discretion at play. This little guy cost me a few hours of my life so at minimum I wanted to open an issue with the error message others might find when they search.

I feel like the real issue is that babel should have rev-ed major with that change. We could maybe ask babel to release 7.23.0 with the old name and then rev major to make 8.0 have the change. That would fix the Rails problem (for some subset of users) as I believe webpack is pessimistically locked against the major version.

@schneems
Copy link
Member Author

schneems commented Jun 2, 2023

I opened babel/babel#15679 to see if they can consider this a bug and rollback the change and move it to 8.x

@rafaelfranca
Copy link
Member

I'm ok to release a new webpacker version if it would help.

This remind me why we moved away from those workflows

@schneems
Copy link
Member Author

schneems commented Jun 6, 2023

I'm ok to release a new webpacker version if it would help.

Thanks! It looks like babel has some suggestions for moving forward. Could you take a look at babel/babel#15679 and let me know if one stands out?

simonbaird added a commit to simonbaird/tiddlyhost that referenced this issue Jun 20, 2023
See rails/rails#48372 as mentioned in the
commentary.

Also revert commit 0ed27d6
which is a previous unsuccessful workaround.
@kaspergrubbe
Copy link

This bit me today, thanks for creating this issue and providing me with a solution. I wish I had googled sooner.

@matthewgani
Copy link

It worked for me after changing both the 'proposal' to 'transform' in babel.config.js as seen in simonbaird's commit above. Thank you guys for providing a fix!

  •     '@babel/plugin-proposal-private-methods',
    
  •     '@babel/plugin-proposal-private-property-in-object',
    

@rails-bot
Copy link

rails-bot bot commented Nov 1, 2023

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 7-1-stable branch or on main, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rails-bot rails-bot bot added the stale label Nov 1, 2023
@deathndark
Copy link

Hi everyone, Good day!
After following the steps above (modifying the babel.config.js), I still get an error in building in heroku.

Done in 13.56s.
       autoprefixer: /tmp/build_0623a275/app/assets/stylesheets/application.scss:25571:3: Replace color-adjust to print-color-adjust. The color-adjust shorthand is currently deprecated.
       autoprefixer: /tmp/build_0623a275/app/assets/stylesheets/chat.scss:25570:3: Replace color-adjust to print-color-adjust. The color-adjust shorthand is currently deprecated.
       Compiling...
       Compilation failed:
       Error: error:0308010C:digital envelope routines::unsupported
           at new Hash (node:internal/crypto/hash:68:19)
           at Object.createHash (node:crypto:138:10)
           at CompressionPlugin.taskGenerator (/tmp/build_0623a275/node_modules/compression-webpack-plugin/dist/index.js:163:38)
           at taskGenerator.next (<anonymous>)
           at /tmp/build_0623a275/node_modules/compression-webpack-plugin/dist/index.js:216:49
           at CompressionPlugin.runTasks (/tmp/build_0623a275/node_modules/compression-webpack-plugin/dist/index.js:236:9)
           at /tmp/build_0623a275/node_modules/compression-webpack-plugin/dist/index.js:270:18
           at _next0 (eval at create (/tmp/build_0623a275/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:37:17)
           at eval (eval at create (/tmp/build_0623a275/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:53:1)
           at WebpackAssetsManifest.handleEmit (/tmp/build_0623a275/node_modules/webpack-assets-manifest/src/WebpackAssetsManifest.js:486:5)
           at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_0623a275/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:49:1)
           at AsyncSeriesHook.lazyCompileHook (/tmp/build_0623a275/node_modules/tapable/lib/Hook.js:154:20)
           at Compiler.emitAssets (/tmp/build_0623a275/node_modules/webpack/lib/Compiler.js:491:19)
           at onCompiled (/tmp/build_0623a275/node_modules/webpack/lib/Compiler.js:278:9)
           at /tmp/build_0623a275/node_modules/webpack/lib/Compiler.js:681:15
           at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_0623a275/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
           at AsyncSeriesHook.lazyCompileHook (/tmp/build_0623a275/node_modules/tapable/lib/Hook.js:154:20)
           at /tmp/build_0623a275/node_modules/webpack/lib/Compiler.js:678:31
           at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_0623a275/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
           at AsyncSeriesHook.lazyCompileHook (/tmp/build_0623a275/node_modules/tapable/lib/Hook.js:154:20)
           at /tmp/build_0623a275/node_modules/webpack/lib/Compilation.js:1423:35
           at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_0623a275/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
           at AsyncSeriesHook.lazyCompileHook (/tmp/build_0623a275/node_modules/tapable/lib/Hook.js:154:20)
           at /tmp/build_0623a275/node_modules/webpack/lib/Compilation.js:1414:32
           at eval (eval at create (/tmp/build_0623a275/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:14:1)
           at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
       

 !
 !     Precompiling assets failed.
 !
 !     Push rejected, failed to compile Ruby app.
 !     Push failed

Is somebody familiar with this issue? thanks

@Mth0158
Copy link

Mth0158 commented Nov 30, 2023

@deathndark it could be because you are using Node >= 17 with Heroku.

You can try several approaches, like:

  • (preferred) Update the packages that cause the error OR
  • Downgrade to Node v16.x OR
  • Enable legacy OpenSSL provider

A lot of options are discussed here.

ometa added a commit to ometa/dogtag that referenced this issue Dec 17, 2023
@victorclee
Copy link

It worked for me after changing both the 'proposal' to 'transform' in babel.config.js as seen in simonbaird's commit above. Thank you guys for providing a fix!

  •     '@babel/plugin-proposal-private-methods',
    
  •     '@babel/plugin-proposal-private-property-in-object',
    

This worked beautifully for me locally 🎉

@rails-bot
Copy link

rails-bot bot commented Mar 20, 2024

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 7-1-stable branch or on main, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rails-bot rails-bot bot added the stale label Mar 20, 2024
@rails-bot rails-bot bot closed this as completed Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants