-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Webpack dependencies fail with npm linked package. #811
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
100% certain these errors happen only after I've npm linked that package in the project. |
Any info I can provide? I can't really provide access to the repo I'm linking because it's internal/private, but maybe there's some useful specific info I can provide? |
Ah, ok. Thanks!! I would've had no idea! |
@sokra This problem isn't intuitive at all. For example, it just happened to me again: krasimir/cssx#15. I think a solution is needed. |
for loaders the behavior was changed to webpack 2. They now resolve relative to the configuration file instead of relative to the affected module |
also related #2937 |
Closing this since it appears to have been fixed in webpack 2. @trusktr, if you still have this issue in webpack 2, please re-open. |
Hi I am using webpack 2 and I cannot figure out why I am having this issue: ERROR in ./src/index.js here the webpack config import path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
export default {
context: path.resolve(__dirname, 'src'),
entry: './index.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'bundle.js',
chunkFilename: 'bundle-[id].js'
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: 'cache/'
}
}
}]
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
minify: {
collapseWhitespace: true
}
}),
],
devtool: "cheap-eval-source-map",
devServer: {
contentBase: path.join(__dirname, "build"),
compress: true,
port: 8080,
open: true
}
}; index.js import internalModule from './module.js';
import externalModule from 'webpack-test-import';
console.log('internal import, ' + internalModule); |
@SpaceK33z no it's not fixed, having the same problem here.
Worse yet, the workaround doesn't work anymore:
|
Same here with webpack 2.x, npm-link'ed modules hangs compilation... |
Same here with webpack 2.x, using yarn link in my case |
Same here, wondering if yarn is the issue. Update: happens with npm as well. Worked for me: Turn off symlink resolution in webpack via |
thanks @erquhart , that helped resolve the issue for me! |
Turning off symlink resolution also makes it so webpack can't watch for changes in the linked dependency :( Any other solutions? |
Actually I'm still having this problem, where I do Any ideas? |
@mesqueeb, I also still experienced this. Tried to play with the What I ended up doing is looking through the For example something like this: const path = require('path');
const projectPath = 'full/path/to/project'
const projectNodeModulesPath = path.resolve(projectPath, 'node_modules');
const modules = [ projectNodeModulesPath ];
await Promise.all((await fse.readdir(projectNodeModulesPath)).map(async el => {
const modulePath = path.resolve(projectNodeModulesPath, el);
if ((await fse.lstat(modulePath)).isSymbolicLink()) {
const realModulePath = path.resolve(await fse.realpath(modulePath), 'node_modules');
resolves.push(realModulePath);
}
})); |
Yeah, what I do is usually Can we re-open this issue? |
I adapted @yuvke 's solution, making it sync and supporting scoped packages. See this gist for a webpack config example. |
@diachedelic that doesn't work for me, same error. |
@chovy could you try printing the results of |
i goofed. i didn't know i had to build the library first. now it works fine w/o any changes. |
@diachedelic solution worked for me as well |
How is this issue still closed when the only solution is a noisy workaround? |
@raffomania Set https://webpack.js.org/configuration/resolve/#resolve-symlinks |
@xthilakx that‘s not an option in the case HMR is needed where webpack needs to watch updates inside of the linked package. This is necessary when developing a library together with the client app. |
This issue should be reopened as it is not properly solved. A module that is linked cannot be debugged with symlinks disabled. |
If you're getting |
In my case following webpack config worked: |
@fabb I understand that it would be awesome to HMR from the linked package, but you should reconsider your development setup if symlinking packages are the only way for you to develop your lib locally. |
@xthilakx I want to develop my lib together with my main app in tandem because it would be faster to get all the requirements right. I can develop the library on its own, and I have Storybook and jest there, but when developing new features for my app, it‘s easy to forget about an edge case, and then I have to build another package version with the fix. And yes, I already have building a new package version optimized to a single click, but it‘s still another roundtrip and takes time to build and then install in my app. |
@fabb I have exactly the same setup as you (Storybook/Jest), but I do not develop my components with projects symlinked using Symlinking has other quirks too, such as this, so I use verdaccio as a local npm registry for testing. Symlinking to develop locally defeats the purpose of using tools like Storybook, IMHO. |
@xthilakx don‘t get me wrong, I love developing my components with storybook, and I would keep doing so. HMR with storybook is much quicker than with my large app. I would just like to be able to quickly try out some changes of the components in my main app without releasing a package version. I use Verdaccio too, since we release our components only for internal use (not open source). |
…ve been added using 'npm link'. See webpack/webpack#811 and https://gist.github.com/diachedelic/6ded48f5c6442482fa69e91ec7ab1742
…ve been added using 'npm link'. See webpack/webpack#811 and https://gist.github.com/diachedelic/6ded48f5c6442482fa69e91ec7ab1742
…ve been added using 'npm link'. See webpack/webpack#811 and https://gist.github.com/diachedelic/6ded48f5c6442482fa69e91ec7ab1742
…ve been added using 'npm link'. See webpack/webpack#811 and https://gist.github.com/diachedelic/6ded48f5c6442482fa69e91ec7ab1742
My project depends on a package that works perfectly when installed normally, but when I
npm link
that package for local development, webpack fails finding dependencies like so:The text was updated successfully, but these errors were encountered: