(This is on a Mac by the way. It seems cp -r
on a Mac is "historical" and should be replaced by cp -R
).
I tried the following:
mkdir TryContext
cd TryContext
npx create-react-app my-app
cd my-app
and then I made an app that worked, and npm start
was able to start the server and run it.
But then if I want to make a version 2 of this app, and started by cloning the folder first:
cd ..
cp -r my-app my-app-02
to copy everything to my-app-02
, and cd
into that folder and do npm start
, it will error, saying
> my-app@0.1.0 start /Users/username/code/TryContext/my-app-02
> react-scripts start
internal/modules/cjs/loader.js:800
throw err;
^
Error: Cannot find module '../scripts/start'
I tried different ways, and tried npm rebuild
and then npm start
, and it worked. But I thought if you copy a directory "as is", then using it, npm start
should start the server without needing to do anything? Why was that and what ways besides npm rebuild
could fix it?
TL;RD: when you copy using cp -r
it doesn't really preserve symlinks, it just copies the file contents instead. So npm start
can't find necessary symlink in this particular case. One of the possible solutions is to use cp -a
when coping, which preserves symlinks and avoids this issue.
Mode detailed answer is here