webpack: [BUG?] npm link causes Webpack to look for babel-plugin in linked package node_modules.
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.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 82
- Comments: 41 (3 by maintainers)
Commits related to this issue
- Fixes npm link issue https://github.com/webpack/webpack/issues/1866 — committed to soldotno/aurora-core by SindreSvendby 7 years ago
- Fixes npm link issue https://github.com/webpack/webpack/issues/1866 — committed to soldotno/aurora-core by greenkeeper[bot] 7 years ago
try to add
resolve: { symlinks: false },
to your webpack.configI’m also having the same issue using
babel-plugin-transform-async-to-generator
, I just downgraded frombabel-core@6.7.2
tobabel-core@6.1.21
and it works…Update: Found a workaround:
More info https://github.com/babel/babel-loader/issues/166#issuecomment-196888445
Any update on this?
My workaround (for webpack 3) which is compatible with webpack-dev-server:
First set the
resolve.modules
property:It is important that you supply the abs path to your
node_modules
The, 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 changes{symlinks: false}
fixes the error, however it disrupts webpack’s watch function (and therefore webpack-dev-server will not recompile when changing files in the “linked” dependency).Anybody found another solution?
Any updates on this issue? 😄
I’m avoiding the issue by sticking with
babel-core@6.1.21
, 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 latestwebpack
andwebpack-dev-server
. Just going to wait for a solution.If you’re here you’re probably looking for this solution (at least I was):
http://webpack.github.io/docs/troubleshooting.html#npm-linked-modules-doesn-t-find-their-dependencies
Symlink false does not work with Gatsby which uses webpack 1.
+1
Just a note that the
require.resolve
workaround only works up until Webpack version 1.12.15. Later versions useacorn
instead ofesprima
as the JS parser, and this seems to prevent parsing of the JSON in the query string somehow.Ah, the
require.resolve
trick makes it absolute, circumventing Webpack from looking for the plugin in the wrong place during build? Good workaround!Just opened a PR on watchpack: https://github.com/webpack/watchpack/pull/72
Had a special use case which wasn’t solved by adding
symlinks: false
, and even when I added an exclude rule that made it work, IE10 in a VM wasn’t able to render the page.Since this is the main issue for this kind of problems (at least the first one I landed to), I wanted to share that as suggested by @ganmor here, using https://github.com/wix/wml and avoiding symlinks entirely solved all my issues immediately.
@basham Indeed,
babel-core@6.1.21
works! I’m using that for now, as being able tonpm link
makes dev life a lot easier.I need symlinks for Lerna so I cannot do the symlinks:false trick. @JamesRamm solution worked for me.
Thanks a million @basham! I have been trying to get
npm link
to work withwebpack
andbabel
for some time now, and now it finally works withbabel-core@6.1.21
.This is my webpack config if it helps anyone
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 😕 )
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.