You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
[BUG?] npm link causes Webpack to look for babel-plugin in linked package node_modules. #1866
I've linked a package that is outside of the project by first running npm link in the outside package, then npm link name-of-package inside the project.
I am now getting this error:
Module build failed: ReferenceError: Unknown plugin "transform-es2015-arrow-functions" specified in "base" at 0, attempted to resolve relative to "/path/to/location/far/away/from/project/name-of-package"
Of course there's no babel plugin there.
Reacted by Michael Delaney, Greg Turner, Nicolas Morel, Chris Ginter, Kévin Berthommier, Paul Wisdom, Josh Rieken, Fred, Kyungil Choi, Pavlin Poličar and 72 more
Is there an intention for package authors to depend on certain babel plugins? Maybe that's why this error happens, since the package is outside my project the babel plugin wasn't found there? If that's the case, this would be a feature like how browserify lets developers specify transforms, and wouldn't be a bug, but would need to be documented for library authors to take advantage of.
Nonetheless, it should still work if my project has the needed plugins installed.
@gileze33 Unfortunately I haven't found a workaround. What I'm doing now is just git pushing my package to GitHub, then re-installing the new one each time I push, for development. It's a slower workflow, but at least it works for now. package.json just has the dependency listed something like
I'm avoiding the issue by sticking with [email protected], the latest version I've found that works with npm link. I've been able to upgrade other babel loaders, plugins, and presets without issue in the meantime. I also have the latest webpack and webpack-dev-server. Just going to wait for a solution.
Reacted by Bojan Hribernik, Bono Lv, Chen-Tai Hou, huanglei252 and Edmundo Santos
Ah, good to know! I'll try giving that a shot too.
/#!/JoePea
On Jan 21, 2016 12:15 PM, "Chris Basham" [email protected] wrote:
I'm avoiding the issue by sticking with [email protected], the latest
version that works. I've been able to upgrade other babel loaders, plugins,
and presets without issue in the meantime. Just going to wait for a
solution.
—
Reply to this email directly or view it on GitHub #1866 (comment).
Infer filename from the base directory when resolving plugins and presets.
The issue seems to be that babel plugins now want to be relative to their module, not relative to the main project. Webpack isn't aware of Babel plugins to resolve it like it does with the resolve and resolveLoader configurations. Webpack could potentially solve this, but I'm not convinced it should be Webpack's responsibility to accommodate how babel does its resolving.
This sounds a bit like webpack isn't correctly excluding node_modules. Perhaps there's a symlink resolution issue causing it to run the babel loader on npm linked modules, even though the links are located in node_modules.
Browserify had a very similar bug a while ago, and I experience this bug to be of similar nature.
Update: It looks like this is indeed the case, but that's not the real cause of this issue. I can force webpack to exclude npm linked modules by adding my module name to the list of excludes:
I investigated a bit more and I can reproduce this problem without any usage of babel.
A simple npm linked module and using the brfs transform loader triggers the same issue:
I don't currently have any good workaround for this, except ensuring that you only npm link fully transformed modules. Also, browserify seems to handle all this pretty well (although that's not a good workaround seen from the perspective of this project :/ )
Also experiencing this issue. @basham your suggestion works but doesn't truly solve the problem, just circumvents the issue of webpack loading linked modules from their source directory for the case of transpiling with babel. In my case the babel transform error is gone but my linter (loaded through webpack) is still printing errors for the linked module.
I'm also having the same issue using babel-plugin-transform-async-to-generator, I just downgraded from [email protected] to [email protected] and it works...
Reacted by rhgb, Artem Abashev, Kamil Tomšík, Josh Rieken, Charlie Martin, Jure Triglav, TylerBrock, Tianyi, Raphael Wang, Stephen Wicklund and 12 more
Reacted by Luke Schoen, Tianyi, Raphael Wang, Alfonso Garcia-Caro, Slava, Kyle Holzinger, aesopwolf, Brett Beutell, Wagner Santos, Craig Palermo and 2 more
I believe plugins also suffer from this bug.
I'm using the ProvidePlugin to bind the three.js library to THREE:
new webpack.ProvidePlugin({
THREE: 'three'
}),
This triggers the Module not found: Error: Cannot resolve module 'three' in ... error in my npm linked modules.
I did not manage to get the require.resolve trick to work for my babel setup. My workaround is to manually exclude regexps matching my linked modules.
The trick does work as a workaround for the provide plugin though.
I found the same as @wmzy after my own lengthy investigation. I have opened an issue on watchpack's issue tracker to make that option configurable: webpack/watchpack#61
Something I did which isn't the most ideal is just install the babel plugin as a devDependency in the module you are linking into your project. The babel-plugin-dynamic-import-node was the culprit for me so I just installed that. Errors cleared up and I can continue working on my package. Pretty much just a time saver so I can stop looking into this issue and move forward.
Note this means you need to explicitly move any babel setup you have in a babelrc file into your webpack config (in my case it was moving the plugins defs)
This compiles and when I make a change in a yarn link'd module, dev-server is picking up the changes
Reacted by Vitali Kuzmich, Joel, David Welling, Artur Arseniev, Luca Tagliaferri, Edmundo Santos, Ross Chapman (he/him), Mikhail Pilov, eqyiel, Leho Kraav and 3 more
Reacted by David Welling, Leho Kraav and Jarek Kuboš
Activity
trusktr commentedon Jan 8, 2016
Is there an intention for package authors to depend on certain babel plugins? Maybe that's why this error happens, since the package is outside my project the babel plugin wasn't found there? If that's the case, this would be a feature like how browserify lets developers specify transforms, and wouldn't be a bug, but would need to be documented for library authors to take advantage of.
Nonetheless, it should still work if my project has the needed plugins installed.
gileze33 commentedon Jan 18, 2016
Just ran into the same issue, did you manage to find a work around?
npm linkis obviously super important for our workflowtrusktr commentedon Jan 18, 2016
@gileze33 Unfortunately I haven't found a workaround. What I'm doing now is just
git pushing my package to GitHub, then re-installing the new one each time I push, for development. It's a slower workflow, but at least it works for now.package.jsonjust has the dependency listed something liketo get it from GitHub. I can then just change it to a version number once I publish a version on NPM.
basham commentedon Jan 21, 2016
I'm avoiding the issue by sticking with
[email protected], the latest version I've found that works withnpm link. I've been able to upgrade other babel loaders, plugins, and presets without issue in the meantime. I also have the latestwebpackandwebpack-dev-server. Just going to wait for a solution.trusktr commentedon Jan 21, 2016
Ah, good to know! I'll try giving that a shot too.
/#!/JoePea
On Jan 21, 2016 12:15 PM, "Chris Basham" [email protected] wrote:
trusktr commentedon Jan 23, 2016
@basham Indeed,
[email protected]works! I'm using that for now, as being able tonpm linkmakes dev life a lot easier.trusktr commentedon Jan 23, 2016
Oh, wait, so is this an issue with Babel, not Webpack?
basham commentedon Jan 25, 2016
I highly suspect it is due to this
6.2.0change:The issue seems to be that babel plugins now want to be relative to their module, not relative to the main project. Webpack isn't aware of Babel plugins to resolve it like it does with the
resolveandresolveLoaderconfigurations. Webpack could potentially solve this, but I'm not convinced it should be Webpack's responsibility to accommodate how babel does its resolving.kintel commentedon Feb 21, 2016
This sounds a bit like webpack isn't correctly excluding node_modules. Perhaps there's a symlink resolution issue causing it to run the babel loader on npm linked modules, even though the links are located in node_modules.
Browserify had a very similar bug a while ago, and I experience this bug to be of similar nature.
Update: It looks like this is indeed the case, but that's not the real cause of this issue. I can force webpack to exclude npm linked modules by adding my module name to the list of excludes:
Of course, this only helps if you don't want to run the transform. If you do, the originally reported issue is still present. See below for more info.
kintel commentedon Feb 22, 2016
I investigated a bit more and I can reproduce this problem without any usage of babel.
A simple npm linked module and using the brfs transform loader triggers the same issue:
I don't currently have any good workaround for this, except ensuring that you only npm link fully transformed modules. Also, browserify seems to handle all this pretty well (although that's not a good workaround seen from the perspective of this project :/ )
slightlytyler commentedon Feb 25, 2016
Also experiencing this issue. @basham your suggestion works but doesn't truly solve the problem, just circumvents the issue of webpack loading linked modules from their source directory for the case of transpiling with babel. In my case the babel transform error is gone but my linter (loaded through webpack) is still printing errors for the linked module.
zzarcon commentedon Mar 30, 2016
I'm also having the same issue using
babel-plugin-transform-async-to-generator, I just downgraded from[email protected]to[email protected]and it works...Update: Found a workaround:
More info babel/babel-loader#166 (comment)
Any update on this?
trusktr commentedon Apr 7, 2016
Ah, the
require.resolvetrick makes it absolute, circumventing Webpack from looking for the plugin in the wrong place during build? Good workaround!kintel commentedon Apr 15, 2016
I believe plugins also suffer from this bug.
I'm using the
ProvidePluginto bind the three.js library to THREE:This triggers the
Module not found: Error: Cannot resolve module 'three' in ...error in my npm linked modules.I did not manage to get the require.resolve trick to work for my babel setup. My workaround is to manually exclude regexps matching my linked modules.
The trick does work as a workaround for the provide plugin though.
16 remaining items
wmzy commentedon Dec 26, 2017
@joaoreynolds
Let the
followSymlinksto betruework for me : node_modules/watchpack/lib/DirectoryWatcher.js#L52But why not webpack turn on the
followSymlinksoption whensymlinksisfalse?txinfo commentedon Jan 16, 2018
I found the same as @wmzy after my own lengthy investigation. I have opened an issue on watchpack's issue tracker to make that option configurable: webpack/watchpack#61
nreoch25 commentedon Jan 25, 2018
Something I did which isn't the most ideal is just install the babel plugin as a devDependency in the module you are linking into your project. The babel-plugin-dynamic-import-node was the culprit for me so I just installed that. Errors cleared up and I can continue working on my package. Pretty much just a time saver so I can stop looking into this issue and move forward.
mbardelmeijer commentedon Feb 2, 2018
Any updates on this issue? 😄
immortal-tofu commentedon Mar 16, 2018
Just opened a PR on watchpack:
webpack/watchpack#72
immortal-tofu commentedon Mar 23, 2018
Add an issue with possible solution feel free to comment or thumbs up this future change.
#6845
JamesRamm commentedon Apr 27, 2018
My workaround (for webpack 3) which is compatible with webpack-dev-server:
First set the
resolve.modulesproperty:It is important that you supply the abs path to your
node_modulesThe, for each babel preset and plugin, explicitly use
require.resolve.Note this means you need to explicitly move any babel setup you have in a babelrc file into your webpack config (in my case it was moving the plugins defs)
This compiles and when I make a change in a
yarn link'd module, dev-server is picking up the changesDaveWelling commentedon May 16, 2018
I need symlinks for Lerna so I cannot do the symlinks:false trick. @JamesRamm solution worked for me.
webpack-bot commentedon Jan 15, 2021
This issue had no activity for at least three months.
It's subject to automatic issue closing if there is no activity in the next 15 days.
alexander-akait commentedon Jan 18, 2021
I think we can close it, nothing to fix on webpack side,
require.resolveis good solution, also can be relevant tot his https://classic.yarnpkg.com/blog/2018/02/15/nohoist/nico-ledesma commentedon May 16, 2022
It's May 2022 and this issue was still present for me:
babel-loaderfailed when processing symlinked packages added vianpm link.Hope this helps!
TL;DR
Add this to
webpack.config.jswhen watching:Long explanation
npm linkin my main project to add symlinked dependencies to other modules.lerna bootstrap.babel-loaderfailed because it was looking forcore-jsandregenerator-runtimein each symlinked modulesnode_modulesdir.webpack@5,@babel/core@7@babel/preset-env@7like this:Solutions that were not working:
require.resolve( @babel/preset-env).resolve.symlinks : falsein Webpack:babel-loaderproblem, but Webpack won't recompile if the symlinked modules change.watchOptions.followSymlinks : truedoesn't fix this Webpack watch problem either.If you can't avoid using
babel-loaderwhen watching, defining those aliases does the trick.alexander-akait commentedon May 16, 2022
@nico-ledesma Can you open a new issue and describe it, we will investigate it, thanks
tofrankie commentedon Jun 21, 2023
👀