Score:0

npm script not able to use executables from node_modules.bin directory

cn flag

My npm script in package.json looks like this:

"build": "$(npm bin)/react-scripts build",

OR

"build": "react-scripts build",

It throws the following error:

Error: Cannot find module '../scripts/build'
Require stack:
- /codebuild/output/src573716697/src/node_modules/.bin/react-scripts
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.resolve (internal/modules/cjs/helpers.js:80:19)
    at Object.<anonymous> (/codebuild/output/src573716697/src/node_modules/.bin/react-scripts:31:23)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/codebuild/output/src573716697/src/node_modules/.bin/react-scripts'
  ]
}

If I change it to:

"build": "./node_modules/react-scripts/bin/react-scripts.js build",

It works, which basically means it is trying to find the scripts folder that is inside the react-scripts folder but not in the bin directory where the react-scripts executable is.

How do I fix this? I'd like to use the executables from my package.json instead and do not like to have to give the entire path to the js script.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.