-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Uncaught TypeError: __webpack_require__(...) is not a function - error on fresh app #2109
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
Comments
For others experiencing this issue, you can remove both the rails tmp:clear Restart your web server and it should work. |
Can you post your |
I have the same error on a fresh app. Update: I actually removed both |
package.json {
"name": "hello",
"private": true,
"dependencies": {
"@rails/actioncable": "^6.0.0-alpha",
"@rails/activestorage": "^6.0.0-alpha",
"@rails/ujs": "^6.0.0-alpha",
"@rails/webpacker": "^4.0.4",
"turbolinks": "^5.2.0"
},
"version": "0.1.0",
"devDependencies": {
"webpack-dev-server": "^3.4.1"
}
} babel.config.js module.exports = function(api) {
var validEnv = ['development', 'test', 'production']
var currentEnv = api.env()
var isDevelopmentEnv = api.env('development')
var isProductionEnv = api.env('production')
var isTestEnv = api.env('test')
if (!validEnv.includes(currentEnv)) {
throw new Error(
'Please specify a valid `NODE_ENV` or ' +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' +
JSON.stringify(currentEnv) +
'.'
)
}
return {
presets: [
isTestEnv && [
require('@babel/preset-env').default,
{
targets: {
node: 'current'
}
}
],
(isProductionEnv || isDevelopmentEnv) && [
require('@babel/preset-env').default,
{
forceAllTransforms: true,
useBuiltIns: 'entry',
corejs: 3,
modules: false,
exclude: ['transform-typeof-symbol']
}
]
].filter(Boolean),
plugins: [
require('babel-plugin-macros'),
require('@babel/plugin-syntax-dynamic-import').default,
isTestEnv && require('babel-plugin-dynamic-import-node'),
require('@babel/plugin-transform-destructuring').default,
[
require('@babel/plugin-proposal-class-properties').default,
{
loose: true
}
],
[
require('@babel/plugin-proposal-object-rest-spread').default,
{
useBuiltIns: true
}
],
[
require('@babel/plugin-transform-runtime').default,
{
helpers: false,
regenerator: true,
corejs: 3
}
],
[
require('@babel/plugin-transform-regenerator').default,
{
async: false
}
]
].filter(Boolean)
}
} |
Same issue here, same package.json and babel.config.js Tried to change the webpacker gem version as suggested above, no luck. Was attempting to get Bootstrap installed, but have moved back to first installation to debug. Further information on my SO thread: https://stackoverflow.com/questions/56366873/cant-install-bootstrap-in-new-rails-6rc1-project-error-in-harmony-module-js |
Doing a completely new project with --skip-webpack-install and changing version before installing webpack. results in a few minutes. |
yes, error persists.
same error running a mac, latest os, latest ruby 2.6.3 |
I have removed the corejs lines from babel.config.js and the error has gone away, but I am now receiving the deprecation warnings |
Experiencing this error as well. Brand new |
dont forget to change the |
Thanks @AmirolAhmad. I totally missed that. |
fwiw, it works for me without changing |
Sorry the noise. It looks like downgrading isn't really needed. All downgrading does is effectively remove the Here's the min difference between working and not working: diff --git a/babel.config.js b/babel.config.js
index b8b230b..f930f3e 100644
--- a/babel.config.js
+++ b/babel.config.js
@@ -30,7 +30,6 @@ module.exports = function(api) {
{
forceAllTransforms: true,
useBuiltIns: 'entry',
- corejs: 3,
modules: false,
exclude: ['transform-typeof-symbol']
}
@@ -57,8 +56,7 @@ module.exports = function(api) {
require('@babel/plugin-transform-runtime').default,
{
helpers: false,
- regenerator: true,
- corejs: 3
+ regenerator: true
}
],
[ |
@ankane I see that you specify Could you test the |
Same issue here: clean Ruby 2.6.3, Rails 6.0.0.rc1 and new app with that error. Think it's safe to say a lot people building a new Rails 6.0.0.rc1 app at the moment are in for some head scratching. Only found this issue and the fix (thanks @ankane !) by explicitly navigating here - Googling will send you on a bit of a goose chase. |
Edit: found a way to reproduce. Looking into it... |
This related issue has led me to a solution: babel/babel#9903 (comment)
I have created a PR to fix this here (works with Edit: You can hotfix by putting this in your environment.js file: environment.loaders.get('nodeModules').exclude = /(?:@?babel(?:\/|\\{1,2}|-).+)|regenerator-runtime|core-js|webpack/; |
OT: Remember when we moved from 4:3 TVs to 16:9? Webpacker feels the same. |
released 4.0.5 |
Hey @jakeNiemiec and @gauravtiwari, thanks for the quick fix. I'm still seeing the same error with Webpacker 4.0.5 unfortunately. Maybe someone else in this thread can also try it? (I reran the repro instructions above and confirmed webpacker 4.0.5 in Gemfile.lock and package.json) |
Perhaps it is the same issue. I have seen similar messages in my setup here. I am trying to run the "Hello vuejs" on Rails 5.2.3, ruby 2.6.1 on a Mac machine. And I get similar messages. Thank you in advance for the assistance. |
Oh I see, it might have to do with |
@ankane I don't think you need the corejs option there require('@babel/plugin-transform-runtime').default,
{
helpers: false,
regenerator: true,
corejs: 3
} since this should be handled by preset-env anyway. Unless I am missing something? |
@ankane @meredoschi Can you tell me if putting: |
Released 4.0.6, thanks @jakeNiemiec BTW, I am wondering would it make sense to make |
Basically something along this line, so we declare packages that needs compiling (should be done by authors but if not) environment.compileNodeModules(['es6-package', 'some-other-es6-package']) |
fwiw, seeing the same error as reported in #2109 (comment) in 4.0.6 |
@ankane Sorry about that. I would say to disable corejs for runtime for now, will look into this properly and propose a fix. require('@babel/plugin-transform-runtime').default,
{
helpers: false,
regenerator: true,
corejs: false // or just remove this line (default is false)
} |
Can confirm: I'm getting the very same error as @ankane is getting with a fresh 4.0.6. |
Can confirm as well. Same error as @d-simon and @ankane with 4.0.6 (updated from a fresh 4.0.4). No errors if I use |
I started testing what For the following, I simply import an empty class from another file:
These gave the same result. The same thing happens if I just
In this one, you can see that no polyfilling is occurring when
It seems like the default babel TL;DR: Take a simple example where I import a class and build for production: https://www.diffchecker.com/MBZsEotj. The plugin is characterized as a |
With v4.0.6 there is a new error [#2114] now (but only if using |
worked for me |
Uncaught TypeError: __webpack_require__(...) is not a function
error on fresh app
Uncaught TypeError: __webpack_require__(...) is not a function
error on fresh app
Everyone with this issue: Please check your personal
PR: #2116 I'm going to keep this issue open for a while to ensure the problem has been fixed for good. |
Awesome, thanks @jakeNiemiec! Can confirm the latest version works on both a fresh and existing app. |
added gem 'gravatar_image_tag' replaced .postcssrc.yml with postcss.config.js fix to babel.config.js (see rails/webpacker#2109 (comment)) add app/javascript/styles/base.css with tailwind imports add stylesheet_pack_tag 'base' to app layout add resolve_paths to config/webpacker.yml add postcss-preset-env, and remove postcss plugins it encompasses play with some example tailwind styles on app/views/pages/hello.html.slim
Fix issues related to this bug rails/webpacker#2109
Think we can close, as this was fixed in the 4.0.7 release. Thanks again @jakeNiemiec |
- Prevents `@babel/plugin-transform-runtime` from rewriting babel helpers in core-js. - Remove unneeded runtime `@babel/runtime-corejs3` cc: rails/webpacker#2031, rails/webpacker#2109
- Prevents `@babel/plugin-transform-runtime` from rewriting babel helpers in core-js. - Remove unneeded runtime `@babel/runtime-corejs3` cc: rails/webpacker#2031, rails/webpacker#2109
Repro Steps
Create fresh rails app
Add a controller and a view, then load it.
Expected Result
JavaScript loads correctly.
Actual Result
May be related to recent release / #2031
The text was updated successfully, but these errors were encountered: