-
-
Notifications
You must be signed in to change notification settings - Fork 27k
Fix importing npm linked libraries #1359
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
Conversation
.map(resolveApp); | ||
.map(resolveApp) | ||
// this allows users to `npm link anyOtherProject` | ||
.concat([ resolveApp('node_modules') ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is slightly confusing to do it here, since this block is specifically for NODE_PATH
.
Can we do this directly in Webpack configs instead?
It's fine to have some duplication in case you're worried about it.
Does this also work with Jest? |
Jest doesn't need anything, it already handles symlinks correctly. I verified by updating my import React from 'react'
import React2 from 'link-example'
test('Import is the same', () => {
expect(React2).toBe(React)
}) So I went ahead and moved my code. When I rebased I discovered that I tried the test plan from this issue against |
The config format has changed in WP2, Could that be the reason? |
I found my problem. |
Need to review this. Tagging for next release. |
Remember that this format is completely different than that of webpack 1, see https://github.com/facebookincubator/create-react-app/blob/0.9.x/packages/react-scripts/config/webpack.config.dev.js#L79-L96. Webpack migration docs said to specify If we merge this, we need to set the |
I understand, I just mean that we should review this as part of the next review cycle, and cherry-pick an equivalent (but maybe different code-wise) fix into 0.9.x if this gets in. |
Sorry if I came off harsh. Just leaving that comment for future reference. @AsaAyers any reason you closed this? |
Haha no worries, just explaining what I mean when I tag PRs because it's probably not super obvious with our branch setup |
We restructured the project that needed this and I'm not interested in figuring out the Webpack1 to Webpack2 conversion here. I completely forgot this was still open until you reminded me today. |
@AsaAyers we still greatly appreciate your contribution and will handle the webpack 1 conversion for you. We'll most likely land this if it works correctly. 😄 |
We'll likely take it over from here, thanks for sending the PR! |
Thanks. This passed the test plan in the body of the PR last time I worked on it. Sorry for the small misunderstanding here. I didn't notice the first message about reviewing and tagging for release. |
Do we actually want to get rid of |
Just tested this, thanks! |
I think this fix was wrong in a strict sense. |
I’m reverting this in #3884. |
Looking through the
npm link
issues, I see two use cases:npm link
to testreact-scripts
npm link
for libraries your app depends on.This PR solves the 2nd case. Webpack's official solution for
npm link
is to add your project's node_modules toresolve.fallback
on the config.To verify the issue and fix create a small library to link:
Then create your app and link the library.
With the current published version, the build will fail:
Even though
my-app
imported./node_modules/link-example/index.js
, the symlink causes webpack to treat it like you required/tmp/link-example/index.js
.