npm start - npm ERR! missing script: start - node.js

I'm receiving this error when trying to my node application using the npm start command.
WhenIi try to npm start I get this error.
Error:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'start' ]
2 info using npm#5.6.0
3 info using node#v8.10.0
4 verbose stack Error: missing script: start
4 verbose stack at run (C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:151:19)
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:61:5
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:115:5
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:402:5
4 verbose stack at checkBinReferences_ (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:357:45)
4 verbose stack at final (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:400:3)
4 verbose stack at then (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:160:5)
4 verbose stack at ReadFileContext.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:332:20)
4 verbose stack at ReadFileContext.callback (C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:78:16)
4 verbose stack at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:420:13)
5 verbose cwd B:\tut\starter
6 verbose Windows_NT 6.1.7601
7 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
8 verbose node v8.10.0
9 verbose npm v5.6.0
10 error missing script: start
11 verbose exit [ 1, true ]
From the debug file:
{
"name": "sridhar",
"version": "1.0.0",
"description": "landing page",
"main": "index.js",
"scripts": {
"compile:sass": "node-sass sass/main.scss css/style.css -w"
},
"author": "sridhar",
"license": "ISC",
"devDependencies": {
"node-sass": "^4.8.3"
}
}

You are missing the entry start in the scripts section of your package.json. If you want to compile the file using npm start then, you should copy node-sass sass/main.scss css/style.css -w and paste it as a value for start. You can add any command you would like to execute as the value for start.
Having said that, if you do npm "compile:sass" it will compile your sass files if you don't want to change your package.json.
"scripts": {
...
"compile:sass": "node-sass sass/main.scss css/style.css -w",
"start": "node-sass sass/main.scss css/style.css -w"
},

Because there is no start script... Just change compile script to start script... Then it will compile your sass files...
"scripts": {
"start": "node-sass sass/main.scss css/style.css -w"
},

npx proved to be more effective to me, instead of using npm after several trials.
The below code worked for me:
npx babel --watch src --out-dir . --presets react-app/prod
It did not require me to manually edit the package.json anymore. Everything went smooth.
For more information please refer to the official documentation page https://reactjs.org/docs/add-react-to-a-website.html#optional-try-react-with-jsx
Cheers

Try removing npx and just use create-react-app itworks

You should remove whatever is there in the script object (If you have just created the project) in package.json file, and put these two lines in.
"start": "webpack-dev-server --mode development --open --hot",
"build": "webpack --mode production"
Folks forget to do that sometimes.And leave the "test" case in. Also make sure you have installed all the dependencies you need for your project, from webpack-cli to other stuff mentioned in the error stack trace.
Hope this works.

Related

Why Laravel Sail NPM say's 'unsupported version of Node.js'?

I'm in a Laravel 8 project using Docker. Actually I'm in designing with SCSS.
My problem comes up, if I try to compile my SCSS. NPM says, my Node version is on 12.x and way to old, but in my container I use Node version 16.5.
I've tried it with the following commands on command line:
./vendor/bin/sail npm run dev
./vendor/bin/sail npm run watch
It runs into this error:
> # watch /var/www/html
> mix watch
Error: You are using an unsupported version of Node. Please update to at least Node v12.14
at assertSupportedNodeVersion (/var/www/html/node_modules/laravel-mix/src/Engine.js:6:15)
at executeScript (/var/www/html/node_modules/laravel-mix/bin/cli.js:61:5)
at Command.program.command.description.option.option.action (/var/www/html/node_modules/laravel-mix/bin/cli.js:39:13)
at Command.listener [as _actionHandler] (/var/www/html/node_modules/commander/index.js:922:31)
at Command._parseCommand (/var/www/html/node_modules/commander/index.js:1503:14)
at Command._dispatchSubcommand (/var/www/html/node_modules/commander/index.js:1443:18)
at Command._parseCommand (/var/www/html/node_modules/commander/index.js:1460:12)
at Command.parse (/var/www/html/node_modules/commander/index.js:1292:10)
at Command.parseAsync (/var/www/html/node_modules/commander/index.js:1318:10)
at run (/var/www/html/node_modules/laravel-mix/bin/cli.js:50:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # watch: `mix watch`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/sail/.npm/_logs/2021-08-28T08_08_14_074Z-debug.log
So I've get into my container with docker exec -it <container-id> /bin/bash. There I look for my actual Node version with node -v. It says, that Node version 16.5 is already installed.
That's the content of the complete log file:
root#c20f3997d228:/var/www/html# cat /home/sail/.npm/_logs/2021-08-28T08_09_07_299Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'dev' ]
2 info using npm#6.14.4
3 info using node#v10.19.0
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle #~predev: #
6 info lifecycle #~dev: #
7 verbose lifecycle #~dev: unsafe-perm in lifecycle true
8 verbose lifecycle #~dev: PATH: /usr/share/npm/node_modules/npm-lifecycle/node-gyp-bin:/var/www/html/node_modules/.bin:/root/.nvm/versions/node/v16.5/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9 verbose lifecycle #~dev: CWD: /var/www/html
10 silly lifecycle #~dev: Args: [ '-c', 'npm run development' ]
11 silly lifecycle #~dev: Returned: code: 1 signal: null
12 info lifecycle #~dev: Failed to exec dev script
13 verbose stack Error: # dev: `npm run development`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:198:13)
13 verbose stack at ChildProcess.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:198:13)
13 verbose stack at maybeClose (internal/child_process.js:982:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid #
15 verbose cwd /var/www/html
16 verbose Linux 5.10.25-linuxkit
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "dev"
18 verbose node v10.19.0
19 verbose npm v6.14.4
20 error code ELIFECYCLE
21 error errno 1
22 error # dev: `npm run development`
22 error Exit status 1
23 error Failed at the # dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
Does anybody has an idea why NPM says, that there is no actual version?
Regards,
Manny
Having come across this same problem myself recently, or more specifically the same wording in the response...
I can state with empirical certainty the issue is NOT your version of NPM, nor is it your version of Node.js, rather it's the version of the dependancy known as "Laravel-mix" which has been pre loaded into your node_modules directory.
In case you aren't aware, the "node_modules" folder is where all your supporting software dependancies get loaded, and increasingly, some of them (like "laravel-mix") are now only supporting very recent versions of Node.js - as in more recent than Mar 2020.
I'm currently seeing this problem pop up on certain versions of Docker, and on versions of Windows 8.1 or earlier. Even AFTER upgrading your version of Node.js the problem is NOT going away because 'laravel-mix" is also cross referencing your Operating System too.
It seems that when "laravel-mix" was upgraded from v5.0 to v6.0 it too fell in to this "very recent versions of Node.js" syndrome. By extension, the default version of "package.json" which now ships with Laravel v8.0 no longer wants 'laravel-mix v5.0", it wants "laravel-mix v6.0".
But there is some good news! Firstly, you do NOT have to use the latest version of "laravel-mix v6.0" in Laravel 8 if you don't want to.
If you do come across this problem, you can work around it by using "parts" of the default version of "package.json" which shipped with Laravel v7.0, which in turn loads the "laravel-mix v5.0" dependancy.
For example... this version of package.json works just great in Laravel 8.0
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.21",
"cross-env": "^7.0.3",
"laravel-mix": "^5.0.1",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"vue-template-compiler": "^2.6.14"
},
"dependencies": {
"tailwindcss": "^3.0.17"
}
}
Make a backup copy of you "package.json" file and edit it similar to above.
It's perfectly OK to delete your "node_modules" folder, along with your "package-lock.json" file in your root directy. After doing this, you can then re-run "npm install" in your terminal.
You will find "npm run dev" will work without errors after performing these steps.

npm run devs fails on a clean install

I'm following a course and when I run npm run dev on the code I just downloaded (and that works in the video) I get this error. I've reinstalled node and npm, deleted node_modules folder and packale-lock.json and ran npm install again, doesnt work.
Here's the output
$ npm run dev
> twittor-server-client#1.0.0 dev C:\Users\Administrador\Desktop\PWA\10-twittor-offline-posting
> ./node_modules/nodemon/bin/nodemon.js server/server
"." no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! twittor-server-client#1.0.0 dev: `./node_modules/nodemon/bin/nodemon.js server/server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the twittor-server-client#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Administrador\AppData\Roaming\npm-cache\_logs\2020-04-12T18_53_06_036Z-debug.log
Here's the debug log:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'dev'
1 verbose cli ]
2 info using npm#6.14.4
3 info using node#v12.16.2
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle twittor-server-client#1.0.0~predev: twittor-server-client#1.0.0
6 info lifecycle twittor-server-client#1.0.0~dev: twittor-server-client#1.0.0
7 verbose lifecycle twittor-server-client#1.0.0~dev: unsafe-perm in lifecycle true
8 verbose lifecycle twittor-server-client#1.0.0~dev: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Administrador\Desktop\PWA\10-twittor-offline-posting\node_modules\.bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Administrador\bin;C:\Program Files\Microsoft MPI\Bin;C:\Python27;C:\Python27\Scripts;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Crucial\Crucial Storage Executive;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Java\jdk1.8.0_201\bin;C:\apache-ant-1.10.7\bin;C:\Users\ Usuario\IdeaProjects\mysql-connector-java-5.1.48;C:\ProgramData\chocolatey\bin;C:\Program Files\dotnet;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn;C:\Program Files\Microsoft SQL Server\140\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn;C:\Program Files\Microsoft SQL Server\140\DTS\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn;C:\Program Files\Git\cmd;C:\Program Files\Microsoft VS Code\bin;C:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn;C:\Program Files\Microsoft SQL Server\150\Tools\Binn;C:\Program Files\Microsoft SQL Server\150\DTS\Binn;C:\MinGW\bin;C:\Program Files\nodejs;C:\Users\Administrador\AppData\Roaming\local\bin;C:\Users\Administrador\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrador\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Administrador\AppData\Roaming\npm
9 verbose lifecycle twittor-server-client#1.0.0~dev: CWD: C:\Users\Administrador\Desktop\PWA\10-twittor-offline-posting
10 silly lifecycle twittor-server-client#1.0.0~dev: Args: [ '/d /s /c', './node_modules/nodemon/bin/nodemon.js server/server' ]
11 silly lifecycle twittor-server-client#1.0.0~dev: Returned: code: 1 signal: null
12 info lifecycle twittor-server-client#1.0.0~dev: Failed to exec dev script
13 verbose stack Error: twittor-server-client#1.0.0 dev: `./node_modules/nodemon/bin/nodemon.js server/server`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:310:20)
13 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:310:20)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid twittor-server-client#1.0.0
15 verbose cwd C:\Users\Administrador\Desktop\PWA\10-twittor-offline-posting
16 verbose Windows_NT 10.0.18362
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
18 verbose node v12.16.2
19 verbose npm v6.14.4
20 error code ELIFECYCLE
21 error errno 1
22 error twittor-server-client#1.0.0 dev: `./node_modules/nodemon/bin/nodemon.js server/server`
22 error Exit status 1
23 error Failed at the twittor-server-client#1.0.0 dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
And the package.json:
{
"name": "twittor-server-client",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server/server.js",
"dev": "./node_modules/nodemon/bin/nodemon.js server/server"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.3"
},
"devDependencies": {
"nodemon": "^1.18.4",
"webpack-dev-server": "^3.10.3"
}
}
Says in the output that the "." in front of the dev script path is not recognized but this is all auto-generated...
I guess, npm cache clean && rm -rf node_modules && npm i should work.
But since you already have nodemon in your dev dependencies. Try
replacing the dev script with "nodemon server/server.js" – Rahul
Sharma Apr 12 at 19:28I guess, npm cache clean && rm -rf node_modules
&& npm i should work. But since you already have nodemon in your dev
dependencies. Try replacing the dev script with "nodemon
server/server.js" – Rahul Sharma Apr 12 at 19:28
This command worked for me:
{
"name": "twittor-server-client",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server/server.js",
"dev": "nodemon server/server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.3"
},
"devDependencies": {
"nodemon": "^1.18.4"
}
}
Hope it can help you #Julian

NPM Run <script> doesn't run any script

When I run any script with npm, no matter in what project, I get errors.
For example when I run npm run start I get the following error:
nasteas-MacBook-Pro:newapp nastea$ npm run start
npm ERR! missing script: start
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/nastea/.npm/_logs/2020-01-02T19_28_32_592Z-debug.log
this is my package.json file:
{
"name": "01-first-app",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"amocrm-api": "^1.3.1"
}
}
These are the logs:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'start' ]
2 info using npm#6.13.4
3 info using node#v12.14.0
4 verbose stack Error: missing script: start
4 verbose stack at run (/usr/local/lib/node_modules/npm/lib/run-script.js:155:19)
4 verbose stack at /usr/local/lib/node_modules/npm/lib/run-script.js:63:5
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:116:5
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:436:5
4 verbose stack at checkBinReferences_ (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:391:45)
4 verbose stack at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:434:3)
4 verbose stack at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:161:5)
4 verbose stack at ReadFileContext.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:350:20)
4 verbose stack at ReadFileContext.callback (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:115:16)
4 verbose stack at FSReqCallback.readFileAfterOpen [as oncomplete] (fs.js:239:13)
5 verbose cwd /Users/nastea/Downloads/nodejs-basics-tutorial-master/01-first-app/newapp
6 verbose Darwin 17.7.0
7 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "start"
8 verbose node v12.14.0
9 verbose npm v6.13.4
10 error missing script: start
11 verbose exit [ 1, true ]
I tried the following:
1. uninstalling and re-installing node.
2. npm config get ignore-scripts returns false
What could be the solution? Any help would be much appreciated.
Later edit: node doesn't run any .js file in terminal either.
Edit: run start works now.

Webpack not being recognized after updates

In my laravel app, after updating to laravel-mix v4, when I run npm run watch, I get the error:
webpack not installed,
consider installing it using npm install
--save-dev webpack
Even when Webpack v4.33.0 is clearly installed & available in my node_modules. Here is my package.json:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
...
"laravel-mix": "^4.0.16",
"webpack": "^4.33.0"
}
}
Here is my webpack.mix.js:
mix.js('resources/assets/js/app.js','public/js/app.js')
.browserSync({
proxy: 'app.test',
notify: false,
open: true,
port: 8080
})
.options({
extractVueStyles: OUTPUTCSS + 'app.css'
});
This wasn't an issue prior to updating my laravel-mix to v4, what seems to be the issue?
--- UPDATE ---
Here is the npm debug log:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'watch' ]
2 info using npm#6.2.0
3 info using node#v10.9.0
4 verbose run-script [ 'prewatch', 'watch', 'postwatch' ]
5 info lifecycle #~prewatch: #
6 info lifecycle #~watch: #
7 verbose lifecycle #~watch: unsafe-perm in lifecycle true
8 verbose lifecycle #~watch: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/main_user/projects/test_project/node_modules/.bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
9 verbose lifecycle #~watch: CWD: /Users/main_user/projects/test_project
10 silly lifecycle #~watch: Args: [ '-c', 'npm run development -- --watch' ]
11 silly lifecycle #~watch: Returned: code: 1 signal: null
12 info lifecycle #~watch: Failed to exec watch script
13 verbose stack Error: # watch: `npm run development -- --watch`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:304:16)
13 verbose stack at EventEmitter.emit (events.js:182:13)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:182:13)
13 verbose stack at maybeClose (internal/child_process.js:961:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:250:5)
14 verbose pkgid #
15 verbose cwd /Users/main_user/projects/test_project
16 verbose Darwin 18.6.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "watch"
18 verbose node v10.9.0
19 verbose npm v6.2.0
20 error code ELIFECYCLE
21 error errno 1
22 error # watch: `npm run development -- --watch`
22 error Exit status 1
23 error Failed at the # watch script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
Found a similar issue over at webpack/webpack-cli#944
this appears to happen when the webpack.config.js module require()s a missing module or requires are not installed using npm
You can also try change webpack-cli version to 2.1.3
Verify you are not using any deprecated plugins. I had to change GlobCopyWebpackPlugin to CopyWebpackPlugin

Preload the env file from custom path

I am trying to preload the .env file when the node application starts.
I have the following configuration but whenever I run npm run start:dev i get error.
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"prestart": "npm run build",
"start": "node .",
"start:dev": "node -r dotenv/config . dotenv_config_path=/.dev.env",
"start:test": "node -r dotenv/config . dotenv_config_path=/.test.env",
"test": "echo \"Error: no test specified\" && exit 1"
},
or
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"prestart": "npm run build",
"start": "node .",
"start:dev": "node -r dotenv/config . dotenv_config_path=./.dev.env",
"start:test": "node -r dotenv/config . dotenv_config_path=./.test.env",
"test": "echo \"Error: no test specified\" && exit 1"
},
My app structure looks like following
Also I have read about not to use multiple config files so I am aware of the drawbacks but I just want to try and see how this will work.
Any help will be appreciated. Thanks!!!
Update#1 -- Error
Error: Cannot find module 'C:\Development\index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! development#1.0.0 start:dev: `node -r dotenv/config index.js dotenv_config_path=/.dev.env`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the development#1.0.0 start:dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\nikhil\AppData\Roaming\npm-cache\_logs\2019-06-05T10_11_48_699Z-debug.log
Log file ---
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'start:dev' ]
2 info using npm#6.4.1
3 info using node#v10.13.0
4 verbose run-script [ 'prestart:dev', 'start:dev', 'poststart:dev' ]
5 info lifecycle development#1.0.0~prestart:dev: development#1.0.0
6 info lifecycle development#1.0.0~start:dev: development#1.0.0
7 verbose lifecycle development#1.0.0~start:dev: unsafe-perm in lifecycle true
8 verbose lifecycle development#1.0.0~start:dev: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Development\node_modules\.bin;
9 verbose lifecycle development#1.0.0~start:dev: CWD: C:\Development
10 silly lifecycle development#1.0.0~start:dev: Args: [ '/d /s /c',
10 silly lifecycle 'node -r dotenv/config index.js dotenv_config_path=/.dev.env' ]
11 silly lifecycle development#1.0.0~start:dev: Returned: code: 1 signal: null
12 info lifecycle development#1.0.0~start:dev: Failed to exec start:dev script
13 verbose stack Error: development#1.0.0 start:dev: `node -r dotenv/config index.js dotenv_config_path=/.dev.env`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:182:13)
13 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:182:13)
13 verbose stack at maybeClose (internal/child_process.js:962:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid development#1.0.0
15 verbose cwd C:\Development
16 verbose Windows_NT 10.0.16299
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "start:dev"
18 verbose node v10.13.0
19 verbose npm v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error development#1.0.0 start:dev: `node -r dotenv/config index.js dotenv_config_path=/.dev.env`
22 error Exit status 1
23 error Failed at the development#1.0.0 start:dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
Problem was with the script section in the package.json file.
There was no prestart:dev which would build the project before starting the server.
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"prestart": "npm run build",
"prestart:dev": "npm run build",
"prestart:test": "npm run build",
"start": "node -r dotenv/config . dotenv_config_path=./.env",
"start:dev": "node -r dotenv/config . dotenv_config_path=./.env.dev",
"start:test": "node -r dotenv/config . dotenv_config_path=./.env.test",
"test": "echo \"Error: no test specified\" && exit 1"
},
You can use the dotenv-cli package, really easy to use :
Here's an example of how I use it :
"create:db:dev:windows": "SET NODE_ENV=development& dotenv -e .env.local sequelize db:create && npx sequelize-cli db:migrate",

Resources