Viewed   357 times

The problem is that when I do npm start OR npm run customScriptCommand npm just not doing anything with the project and quickly just return new line in the terminal.

I've tried removing node and npm from my machine and then do brew installation for node and npm, but it does not fix the problem.

Then I tried removing node and npm from the brew installation and installing it again from nvm, but it also does not fix the problem.

NPM Details

npm -v -> 6.11.3
which npm -> /usr/local/bin/npm

NodeJS Details

node -v -> v12.12.0
which node ->/usr/local/bin/node

Scripts in package.json

"scripts": {
    "start": "node ./bin/www",
    "devstart": "DEBUG=app-name:* nodemon ./bin/www", //I've changed my actual app name to "app-name"

If I do node ./bin/www OR DEBUG=app-name:* nodemon ./bin/www it will work:


  • I've tried on other project that does not have problem on my colleague's machine, with git clone do npm install and tried to run the project, but it still failed

  • Even with fresh project which I just did npm init -y it fail,

   "name": "test"
   "version": "1.0.0",
   "description": "",
   "main": "index.js",
   "scripts": {
       "test": "echo "Error: no test specified" && exit 1"
   "keywords": [],
   "author": "itsme",
   "license": "ISC"



npm config set ignore-scripts false would do the trick for you.

The struggle is real my friend, not following random tutorials from now.

Sunday, August 28, 2022

Below are a couple of solutions to successfully meet your requirement:

Solution A

As noted in @vitorlui's answer the callback parameter is mandatory when using the nodejs built-in fs.rename().

Also when utilizing the node -e command via a npm script it is necessary to wrap the script to evaluate in JSON escaped double quotes, i.e. "...".

  1. For instance, configure the scripts section of your package.json as follows:

    "scripts": {
      "rename": "node -e "require('fs').rename('dist/config/', 'dist/config/conf.json', function(err) { if (err) console.log(err); console.log('File successfully renamed!') })"",
      "copy": "copyfiles -u 2 "src/app/" "dist/config/"",
      "copy-and-rename": "npm run copy && npm run rename"
  2. Then run the following npm command:

    npm run copy-and-rename
  3. On successful completion you should see the following logged to the console after the file has been copied and renamed:

    File successfully renamed!

Solution B

You could also consider installing and utilizing renamer for renaming the file. This may be beneficial if your renaming requirements become more complex than the example provided in your question, or if you want something less verbose than Solution A.

Install and check which version:

  1. cd to your project directory and install renamer by running the following command:

    npm i -D renamer
  2. Then run the following command to check which version of renamer was installed.

    npm ls renamer

Note: The reason I ask you to check which version was installed is because this will determine which of the following renamer commands you should utilize. It differs slightly if the version installed is <0.7.0 or >=0.7.0:

If the version of renamer installed is <0.7.0

  1. Set the scripts section of your package.json to the following:

    "scripts": {
      "rename": "renamer --dry-run -f --regex "^$" -r "conf.json" "dist/config/*"",
      "copy": "copyfiles -u 2 "src/app/" "dist/config/"",
      "copy-and-rename": "npm run copy && npm run rename"
  2. Then run the following npm command:

    npm run copy-and-rename
  3. You should see something like the following logged to your console;

    √ -> distconfigconf.json

    to indicate which pathname was changed.

  4. You'll also notice that the actual filename of the copied file hasn't changed, that's because we included the --dry-run option. Simply omit the --dry-run option from your script and run the command again for the actual file name to be changed.

If the version of renamer installed is >=0.7.0

There was a breaking change since v0.7.0 which included the removal of the --regex option (see here for further info). A regular expression literal is now provided since this version instead.

This change to the API results in the rename script, (as previously shown), needing to be redefined as follows:

"rename": "renamer -f "/^$/" -r "conf.json" "dist/config/*"",
                        ^               ^

Note: The --regex option has been omitted and a regexp is now a literal, i.e. it's now wrapped in a leading and trailing forward slash. Also, in this example the --dry-run option was removed, so reinstate it for testing purposes.

Additional Notes

  • For both Solution A and Solution B, the copying and renaming logic has been added to separate npm scripts, (namely copy and rename respectively) for clarity of explanation. However you can chain the two commands using the && operator instead to form one npm script - the single line will be rather long though :)

  • For Solution B, I often utilize version 0.6.1 of renamer, so I run; npm i -D renamer@0.6.1 to install, as I typically have older versions of nodejs to support. In which case I utilize the --regex flag as per the example shown in the aforementioned sub section titled: "If the version of renamer installed is <0.7.0".

Tuesday, November 8, 2022

Try running npm update and then npm audit. This should fix the problem.

Friday, October 28, 2022

That was an interesting rabbit hole. It is this bug: Prepare doesn't run as root. You could run the container as non-root, but I just used the fix in the issue.

I changed your last line to this

RUN source ~/.nvm/; npm config set unsafe-perm true; npm install jcollard/d3-ng2-service#jcollard/add-dist

Now it fails as expected.

Wednesday, October 26, 2022

I also had the same problem. My prepare script wasn't creating the build directory in the node_modules folder when installing as dependency.

Finally I found out that my .gitignore was the problem, which was setup to ignore the build directory for version control. NPM is inheriting the .gitignore file when no .npmignore can be found, which was the case here.

As stated on

If there’s no .npmignore file, but there is a .gitignore file, then npm will ignore the stuff matched by the .gitignore file

So I solved the problem by simply adding an empty .npmignore in the root.

Wednesday, August 31, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :