-
-
Notifications
You must be signed in to change notification settings - Fork 451
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
babel-loader doesn't transpile imported js from an outside directory #293
Comments
Can you post up your config for
I've never a script import something outside of an entire project. (That's what |
This structure
{
"ignore": [
"node_modules/**/*"
],
"presets": [
"es2015",
"stage-0"
],
"plugins": [
"transform-runtime"
]
}
{
// ...
module: {
// ...
loaders: {
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
}
// ...
}
// ...
} |
Hmm, maybe Babel isn't the one processing it. (This directory structure is unorthodox, since files are being referenced outside of Does it work if you run |
Please rewrite below for
How is it? |
@abouthiroppy yes, it's same code, i just copied part of code, updated below |
@felixexter Are you writing |
@abouthiroppy fixed below, I write |
@felixexter Sorry for my late reply. Did you solve this problem? |
Hi :), I think I get the same problem today. Just to know, for me, If I install the babel-loader (version 5.0.0) instead of 6.2.X, that works. Is it the same for you ? Thank you OK i fix the problem but i don't know really how ... This is my package.json libraries:
And i create a .babelrc file with this lines inside:
and i think that's all :) |
@felixexter What folder is your |
Sometimes it helps to add a |
@kevincaradant No, it doesn't work for me. |
@loganfsmyth |
@felixexter Try to place |
I have a similar problem. Babel doesn't transpile js-files. |
Hi, i have the same issue. I have asked a question in stackoverflow to see if anyone has a solution for that.
@inkorcoder |
@samsul003, Hi, really sorry but I didn't remember, and when I see my answer, I don't know. I think the configuration suggested in my previous message is the thing which resolved my problem but maybe it's not the case of everyone :/ |
Hi, i got it solved. As it seems to me it doesnt really matter which version of the babel core, babel-loader you actually use. Also .babelrc file was not required for me. What worked for me was to include the bundled file in my HTML which was generated at |
Remember to include the output file and not the input one. this: to: |
Ran into a similar issue today. This was my folder structure:
Now, {
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
} The solution that helped me was to remove {
test: /\.jsx?$/,
use: {
loader: 'babel-loader',
options: {
presets: [
require.resolve('babel-preset-react'),
[require.resolve('babel-preset-es2015'), { "modules": false }],
require.resolve('babel-preset-stage-0')
]
}
},
exclude: /node_modules/
} I suspect there's a problem with package paths if you don't resolve the path at build time. |
@felixexter I also Ran into a similar issue. When I tried to find the reason, I add the console.log and it work. Maybe you can try it. // ../test/index.js
import muliply from './multiply'
console.log('The strange bug');
export default (a, b) => muliply(a, b) |
I have a similar issue when imported module is linked. In order to isolate it I created a simple project: https://github.com/mass85/no_transpilation_with_lerna Could anyone be so kind and have a look at this and try to fix it? |
I have the same issue as @mass85. |
This just started happening with me using a yarn monorepo. Previously, the problem was resolved by adding the appropriate (linked) paths to the webpack E.g.,
|
Have you updated to a new Webpack version or anything? |
I resolved my issue and may have a solution for folks (Webpack 2). If you're in doubt install
|
I have a very similar issue in a monorepo. Adding a .babelrc to the exterior file's parent and that started it working, but a different build broke because it was using an old version of babel that doesn't support |
Discovered while doing this some weirdness involving babel transpilation. gherkin-runner wasn't getting transpiled when tests run. Found some discussion of the issue, including an indication that a fix is due out in jest soon: jestjs/jest#4761 I updated jest to 21.3.0-beta.3 to see if that helped. It didn't at first, which turned out to be because it wasn't under the original package directory, so babel didn't know what transforms to run (?). (These thoughts are based on discussion here:) babel/babel-loader#293 I added some babel configuration to the root-level package.json which fixed the issue.
I ran into the same issue today! The example repo (https://github.com/mass85/no_transpilation_with_lerna) does a good job capturing the problem. I did notice (along with @thedamon) that when I move One thing that seemed to have helped was explicitly setting the {
test: /\.js$/,
loader: "babel-loader",
include: [
path.resolve(__dirname, "src"),
path.resolve(__dirname, "../../packages"),
],
query: Object.assign(
{
babelrc: false,
cacheDirectory: false,
}
require("./my-babel-preset")
),
} |
I have a similar problem, hope it helps. I have an app project that builds successfully, and I have it as dependency of an |
Is this problem solved ? I´m running the same issue as @felixexter |
Having the same problem here. I have two repos -- a Vue component, and a demo/test site for said component. I want to have them pulled in sister folders and use the demo site to test live changes I'm making in the Vue components. |
The same issue going on, I have a utility that needs to import Class File from a package outside the folder ( Its model definition for a database) from a sister project, I mean, it should just transpile the imported file as if it was same dir import, I can't see why this does not work out of the box, to be honest. |
I had the same issue here, I wanted to keep my
const babelConfig = JSON.parse(fs.readFileSync('.babelrc'));
...
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: babelConfig.presets.map(preset => [require.resolve(`babel-preset-${preset}`), { "modules": false }]),
plugins: babelConfig.plugins.map(plugin => require.resolve(`babel-plugin-${plugin}`)),
}
},
}, No config needed in external folder, and my
|
I have the same issue with a monorepo, and my working solution is adapted from @ViBiOh's above: {
loader: 'babel-loader',
options: {
presets: babelConfig.presets.map((preset) => [preset, { modules: false }]),
plugins: babelConfig.plugins.map((plugin) => {
if (typeof plugin === 'string') return plugin
return [...plugin]
}),
},
}, .babelrc: {
"presets": ["@babel/preset-react", "@babel/preset-flow", "@babel/preset-env"],
"env": {
"development": {
"plugins": ["flow-react-proptypes"]
}
},
"plugins": [
[
"babel-plugin-module-resolver",
{
"root": ["./app"],
"extensions": [".js", ".web.js", ".native.js"],
"alias": {
"App": "./app/"
},
"cwd": "babelrc"
}
],
"babel-plugin-styled-components",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
"react-hot-loader/babel",
"ramda"
]
} My solution was a little different because one of my plugins has configuration options. I should also note that this doesn't use
|
Same issue here. This is my folder structure:
...
Webpack resolves filename normally, but for some reason babel-loader is trying to find all the plugins not at the project directory, but from the /common folder. So I get something like that:
But if copy node_modules from the project folder to the common, it's starts working as is should be. PS: Babel-loader 7.x.x, this bug is too years old:) |
Hi, in my case I have two entry files called
I need |
Workaround for when this problem arises when depending on a sibling lerna package: |
I'm triaging old issues on babel-loader. Since this has been inactive for ages, I'm going to close it. Feel free to re-open if there's still something to discuss, but I'm assuming at this point it's been too long to address in a useful way. The issue is that |
I had this same issue and tried a few fixes here that didn't solve it. My directory structure is: project-1 imported some modules from project-2 (temporarily!) and was erroring because the 'babel-plugin-transform-object-rest-spread' plugin was not working. My parent/project-1/webpack.config.js used to be:
And parent/project-1/.babelrc
It started working by removing
You also must have the babel plugins installed in both project-1/node_modules and project-2/node_modules. |
I place |
My fix was to add another route to the includes array. I was referencing certain file from another package outside my current package, so did this for both JS and CSS rules in Before
After
|
Webpack Version: 1.13.2
Babel Core Version: 6.14.0
Babel Loader Version: 6.2.5
Environment: Windows 7
I'm trying to import a script from an outside app directory
It should be transpiled to es5, but i get an error in browser console:
Is it a bug or a feature and I need to config something else?
The text was updated successfully, but these errors were encountered: