Created by: AsaAyers
Looking through the npm link
issues, I see two use cases:
- (#1356) using
npm link
to testreact-scripts
- using
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 to resolve.fallback
on the config.
To verify the issue and fix create a small library to link:
cd /tmp
git clone https://gist.github.com/f40e1bad454626691097b4cc4651208c.git link-example
cd link-example
npm link
# to clean this up when you're done, return and run `npm unlink`
Then create your app and link the library.
create-react-app my-app
cd my-app
npm link link-example
echo 'import "link-example"' > src/index.js
npm run build
With the current published version, the build will fail:
> my-app@0.1.0 build /tmp/my-app
> react-scripts build
Creating an optimized production build...
Failed to compile.
Module not found: Error: Cannot resolve module 'react' in /tmp/link-example
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
.
Activity
Created by: AsaAyers
Jest doesn't need anything, it already handles symlinks correctly. I verified by updating my
link-example
to:module.exports = require('react')
. Then I created a test file inmy-app
: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
master
already has my change in both files. webpack.conf.dev.js and webpack.config.prod.js.I tried the test plan from this issue against
master
, and I the problem isn't actually fixed. My best guess is that this solution doesn't work with Webpack 2.Created by: Timer
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
'node_modules'
as the default, see https://webpack.js.org/guides/migrating/#resolve-root-resolve-fallback-resolve-modulesdirectories.If we merge this, we need to set the
root
property in the 0.9.x branch. The current PR only fixes this for webpack 2.Created by: gaearon
I think this fix was wrong in a strict sense. See https://github.com/facebookincubator/create-react-app/issues/3883.
Created by: gaearon
I’m reverting this in https://github.com/facebookincubator/create-react-app/pull/3884.