-
-
Notifications
You must be signed in to change notification settings - Fork 448
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
.babelrc not working #552
Comments
From spelunking the same code, it appears that |
I've attempted to fix this problem in a PR, some help with writing the test would be so much appreciated. |
@nguyenj I think a better approach might be to highlight in the documentation that you have to set |
None of the above solutions worked for me, but this is:
So actually, I'm getting the .babelrc file and use it's contents as the options for babel-loader |
I have this code in my .babelrc and its working for me.
For more, I have my
and
I would like to tell you that I am using React with Semantic-ui-react and this configuration is rocking. You can try. If you face any error tell me. |
I see the real issue now after some more investigation, @al-the-x just to point out that
So the issue can be resolved in two ways:
The babelrc path gets assign here, and then gets removed here, and transpile doesn't get it. Where it needs to get added separately is here. |
Just to note, this is for |
In my case using |
That's not how I read that code, @nguyenj: // https://github.com/babel/babel-loader/blob/7.x/src/index.js#L116-L122
if (loaderOptions.babelrc !== false) {
babelrcPath =
typeof loaderOptions.babelrc === "string" &&
exists(fileSystem, loaderOptions.babelrc)
? loaderOptions.babelrc
: resolveRc(fileSystem, path.dirname(filename));
} Refactored for more clarity using some lodash operations not in the original: if (loaderOptions.babelrc !== false) { // if not explicitly `false`
if (_.isString(loaderOptions.babelrc)) { // `babelrc` is a string value
if (exists(fileSystem, loaderOptions.babelrc)) { // `babelrc` refers to an existing file
babelrcPath = loaderOptions.babelrc; // use the file that `babelrc` refers to
} else { // `babelrc` is _not_ a filename, so any non-string, non-`false` value, including `true`
babelrcPath = resolveRc(fileSystem, path.dirname(filename));
// use `resolveRc` to find the appropriate RC file relative to the `filename` from the `require` request
}
} This explains the positive experience (boolean pun!) that @thasmo and I had:
Nice bit of detective work tracing the The shorthand |
To set the defaults properly, I think we'd modify Line 113 in b9f4d60
const loaderOptions = Object.assign({ }, {
babelrc: true
}, loaderUtils.getOptions(this) || { }); I may have just volunteered myself for a PR. 💩 |
Actually re-re-reading it, I'm not sure why the existing logic is not tripping when the Well, I opened a PR anyway. Someone can tell me why I'm an idiot. |
Which version of the Babel 6 wasn't changed in months, besides for security updates, so it would be odd that this started happening now and not before and So I'm a little bit confused about the versions. Does anyone have a working testcase/repository to reproduce this? |
Using the latest beta for all babel packages. |
Can you please test again with 8.0.0-beta.1. It should be fixed now. https://github.com/babel/babel-loader/releases/tag/v8.0.0-beta.1 |
As for the versions, I am using these:
|
I have the same problem. My versions is:
|
Please try using the latest version |
You’re asking people to upgrade a major version because its fixed. Just to get this working they need to upgrade to Babel 7, that’s not a good solution especially if you’re working on a large team. On another note, I did some more investigation and noticed that babel-core doesn’t read
|
No I'm talking about
Anyway if you happen to have a reproducible case where I can test that would help. :) |
The workaround that I shared, setting |
@al-the-x I readed the babel-laoder's code, if babelrc is not false, it will find the .babelrc file from the executing directory, which not like node. But if the babelrc is string, like: babelrc: path.resolve(__dirname + "/.babelrc"), it works. But there is another thing, env is not founded, because the presets env is also be read from the excuting directory, it makes me crazy! So, I think we should not use the .babelrc file but config the babel options in the webpack.config.js file! |
Setting |
Direct read of .babelrc is helped for me:
|
I was successfully using @finom's solution above. After upgrading to the official Babel 7 release, due to other issues, I eventually had to migrate Then I was able to remove that |
I'm not sure there's anything actionable for us here, so I'm going to close this. Babel 7 + |
Even with a babel.config.js I could not get it to work - only @finom solution worked for me. I have the following structure:
running the dev server (that reads webpack.config.js) makes babel-loader not to read the |
@pietrofxq |
How am I supposed to use fs in webpack? It is not defined. |
@skukan159 |
- add 1 simple test for existence of canvas and instance methods - change test script to use jest, and move prev test to test:pub - change CI to run test and test:pub - configure jest and enzyme for testing usage - make jest importable too - add .babelrc to configure babel-jest - can't use .babelrc.js as babel-jest@23 doesn't support it - jestjs/jest#5324 - can't use .babelrc for babel-loader because babel-loader@6 has some bugs with it and @7 doesn't support webpack@1 - babel/babel-loader#552 - use jest instead of ava mainly because there's less to configure / install (directly at least, still a lot indirectly), it's popular / well-supported in React community, and supports configuration outside of package.json - see #33 for some more details (deps): add jest, enzyme, and supporting deps to devDeps - add babel-jest@23 for Babel 6 support - and configure it for .js files due to a jest bug - add canvas-prebuilt@1 to support jest's jsdom v11 - canvas is used by jsdom for, well, canvas interactions - add enzyme-adapter-react-16 to configure Enzyme with React 16 - upgrade to React 16 in devDeps bc adapter-react-15 requires react-test-renderer and no drawbacks in upgrading
- add 1 simple test for existence of canvas and instance methods - change test script to use jest, and move prev test to test:pub - change CI to run test and test:pub - configure jest and enzyme for testing usage - make jest importable too - add .babelrc to configure babel-jest - can't use .babelrc.js as babel-jest@23 doesn't support it - jestjs/jest#5324 - can't use .babelrc for babel-loader because babel-loader@6 has some bugs with it and @7 doesn't support webpack@1 - babel/babel-loader#552 - use jest instead of ava mainly because there's less to configure / install (directly at least, still a lot indirectly), it's popular / well-supported in React community, and supports configuration outside of package.json - see #33 for some more details (deps): add jest, enzyme, and supporting deps to devDeps - add babel-jest@23 for Babel 6 support - and configure it for .js files due to a jest bug - add canvas-prebuilt@1 to support jest's jsdom v11 - canvas is used by jsdom for, well, canvas interactions - add enzyme-adapter-react-16 to configure Enzyme with React 16 - upgrade to React 16 in devDeps bc adapter-react-15 requires react-test-renderer and no drawbacks in upgrading
- add 1 simple test for existence of canvas and instance methods - (pkg): test code shouldn't be in the package, just source - currently preferring to keep source and tests co-located - change test script to use jest, and move prev test to test:pub - change CI to run test and test:pub - configure jest and enzyme for testing usage - make jest importable too - add .babelrc to configure babel-jest - can't use .babelrc.js as babel-jest@23 doesn't support it - jestjs/jest#5324 - can't use .babelrc for babel-loader because babel-loader@6 has some bugs with it and @7 doesn't support webpack@1 - babel/babel-loader#552 - use jest instead of ava mainly because there's less to configure / install (directly at least, still a lot indirectly), it's popular / well-supported in React community, and supports configuration outside of package.json - see #33 for some more details (deps): add jest, enzyme, and supporting deps to devDeps - add babel-jest@23 for Babel 6 support - and configure it for .js files due to a jest bug - add canvas-prebuilt@1 to support jest's jsdom v11 - canvas is used by jsdom for, well, canvas interactions - add enzyme-adapter-react-16 to configure Enzyme with React 16 - upgrade to React 16 in devDeps bc adapter-react-15 requires react-test-renderer and no drawbacks in upgrading
- add 1 simple test for existence of canvas and instance methods - (pkg): test code shouldn't be in the package, just source - currently preferring to keep source and tests co-located - change test script to use jest, and move prev test to test:pub - (ci): change CI to run test and test:pub - configure jest and enzyme for testing usage - make jest importable too - add .babelrc to configure babel-jest - can't use .babelrc.js as babel-jest@23 doesn't support it - jestjs/jest#5324 - can't use .babelrc for babel-loader because babel-loader@6 has some bugs with it and @7 doesn't support webpack@1 - babel/babel-loader#552 - use jest instead of ava mainly because there's less to configure / install (directly at least, still a lot indirectly), it's popular / well-supported in React community, and supports configuration outside of package.json - see #33 for some more details (deps): add jest, enzyme, and supporting deps to devDeps - add babel-jest@23 for Babel 6 support - and configure it for .js files due to a jest bug - add canvas-prebuilt@1 to support jest's jsdom v11 - canvas is used by jsdom for, well, canvas interactions - add enzyme-adapter-react-16 to configure Enzyme with React 16 - upgrade to React 16 in devDeps bc adapter-react-15 requires react-test-renderer and no drawbacks in upgrading
- add 1 simple test for existence of canvas and instance methods - (pkg): test code shouldn't be in the package, just source - currently preferring to keep source and tests co-located - change test script to use jest, and move prev test to test:pub - (ci): change CI to run test and test:pub - configure jest and enzyme for testing usage - make jest importable too - add .babelrc to configure babel-jest - can't use .babelrc.js as babel-jest@23 doesn't support it - jestjs/jest#5324 - can't use .babelrc for babel-loader because babel-loader@6 has some bugs with it and @7 doesn't support webpack@1 - babel/babel-loader#552 - use jest instead of ava mainly because there's less to configure / install (directly at least, still a lot indirectly), it's popular / well-supported in React community, and supports configuration outside of package.json - see #33 for some more details (deps): add jest, enzyme, and supporting deps to devDeps - add babel-jest@23 for Babel 6 support - and configure it for .js files due to a jest bug - add canvas-prebuilt@1 to support jest's jsdom v11 - canvas is used by jsdom for, well, canvas interactions - add enzyme-adapter-react-16 to configure Enzyme with React 16 - upgrade to React 16 in devDeps bc adapter-react-15 requires react-test-renderer and no drawbacks in upgrading
- ensure that width/height of canvas are trimmed down after drawing a purple rectangle in the center - add test script that uses jest - (ci): change CI to run test and test:pub - configure jest and babel-jest - add coverage/ directory to gitignore - add babel-jest@23 for Babel 6 support - and configure it for .js files due to a jest bug - add .babelrc to configure babel-jest - can't use .babelrc.js as babel-jest@23 doesn't support it - jestjs/jest#5324 - can't use .babelrc for babel-loader (have to duplicate config) because babel-loader@6 has some bugs with it and babel-loader@7 doesn't support webpack@1 - babel/babel-loader#552 (deps): add jest, babel-jest, and canvas-prebuilt to devDeps - add canvas-prebuilt@1 to support jest's jsdom v11 - canvas is used by jsdom for, well, canvas interactions
- ensure that width/height of canvas are trimmed down after drawing a purple rectangle in the center - add test script that uses jest - (ci): change CI to run test and test:pub - configure jest and babel-jest - add coverage/ directory to gitignore - add babel-jest@23 for Babel 6 support - and configure it for .js files due to a jest bug - add .babelrc to configure babel-jest - can't use .babelrc.js as babel-jest@23 doesn't support it - jestjs/jest#5324 - can't use .babelrc for babel-loader (have to duplicate config) because babel-loader@6 has some bugs with it and babel-loader@7 doesn't support webpack@1 - babel/babel-loader#552 (deps): add jest, babel-jest, and canvas-prebuilt to devDeps - add canvas-prebuilt@1 to support jest's jsdom v11 - canvas is used by jsdom for, well, canvas interactions
- ensure that width/height of canvas are trimmed down after drawing a purple rectangle in the center - add test script that uses jest - (ci): change CI to run test and test:pub - configure jest and babel-jest - add coverage/ directory to gitignore - add babel-jest@23 for Babel 6 support - and configure it for .js files due to a jest bug - add .babelrc to configure babel-jest - can't use .babelrc.js as babel-jest@23 doesn't support it - jestjs/jest#5324 - can't use .babelrc for babel-loader (have to duplicate config) because babel-loader@6 has some bugs with it and babel-loader@7 doesn't support webpack@1 - babel/babel-loader#552 (deps): add jest, babel-jest, and canvas-prebuilt to devDeps - add canvas-prebuilt@1 to support jest's jsdom v11 - canvas is used by jsdom for, well, canvas interactions
- ensure that width/height of canvas are trimmed down after drawing a purple rectangle in the center - add test script that uses jest - (ci): change CI to run test and test:pub - configure jest and babel-jest - add coverage/ directory to gitignore - add babel-jest@23 for Babel 6 support - and configure it for .js files due to a jest bug - add .babelrc to configure babel-jest - can't use .babelrc.js as babel-jest@23 doesn't support it - jestjs/jest#5324 - can't use .babelrc for babel-loader (have to duplicate config) because babel-loader@6 has some bugs with it and babel-loader@7 doesn't support webpack@1 - babel/babel-loader#552 (deps): add jest, babel-jest, and canvas-prebuilt to devDeps - add canvas-prebuilt@1 to support jest's jsdom v11 - canvas is used by jsdom for, well, canvas interactions
@al-the-x Where can I find this option please! |
@mohsenuss91 Posting the same question in a lot of closed issues won't get you an answer if you don't provide more info. Please, share your current configuration, your files/directories structure, the behavior you are seeing and the behavior you are expecting. |
@mohsenuss91 |
I have folled a very simple tutorial to set up webpack, babel and react, but get an error with the presets when I use a
.babelrc
file.webpack.config.js:
.babelrc:
Gets me the following error:
If I change my webpack.config.js file to this instead it works:
From my understanding having the options object or a .babelrc file should do the same thing. But only one of them works.
I don't have a
"babel": {}
block within my package.json so I really don't see why it seems that the .babelrc file is not recognized.The text was updated successfully, but these errors were encountered: