简体   繁体   中英

How to run build script in CRA when node_modules is in parent directory?

I have a file structure that looks like this:

/client
  |--/src 
  |--package.json
  |--/build
/controllers
/models
app.js
package.json
/node_modules

My client folder has all of the CRA stuff in it, however I gutted the package.json file to only include the scripts. Client has none of the dependencies as I moved them into the parent package.json file. The start script works exactly like it should. However when I run the build script I get the following error:

'react-scripts' is not recognized as an internal or external command,

I've tried removing node_modules and reinstalling but that hasn't fixed the problem. This leads me to believe that the build script is looking for the react-scripts in the same directory that the client package.json is in. I can't just move the build script up to the parent directory though as then it can no longer locate the index.html file. Anyone know of a way to help react-scripts be found in the parent directory before I'm forced to have 2 node_modules?

所以我发现在父目录中使用这个命令让我们的 react-scripts 知道在哪里寻找 node_modules

"build": "npm run build --prefix client",

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM