Preload the env file from custom path - node.js

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",

Related

npm installation eroor on fresh laravel 8 app

I am using laragon. Created a fresh laravel 8 app. Installed Jetstream and livewire. Then tried running npm install && npm run dev. but getting error.
I have tried Delete node_modules folder and package-lock.json
reinstall package using npm install
Cleared npm cache
Tried run npm run dev again but didn't help.
my package.json
{
"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",
"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\""
},
"devDependencies": {
"#tailwindcss/forms": "^0.4.0",
"#tailwindcss/typography": "^0.5.0",
"alpinejs": "^3.0.6",
"axios": "^0.19",
"cross-env": "^7.0",
"laravel-mix": "^6.0.43",
"lodash": "^4.17.19",
"postcss-import": "^14.0.1",
"resolve-url-loader": "^3.1.0",
"tailwindcss": "^3.0.0",
"vue-template-compiler": "^2.6.14"
}
}
My log file:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\laragon\\bin\\nodejs\\node-v14\\node.exe',
1 verbose cli 'C:\\laragon\\bin\\nodejs\\node-v14\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'dev'
1 verbose cli ]
2 info using npm#6.14.12
3 info using node#v14.16.1
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: C:\laragon\bin\nodejs\node-v14\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\laragon\www\school\node_modules\.bin;C:\Users\This pc\AppData\Local\Yarn\config\global\node_modules\.bin;C:\Users\This pc\AppData\Roaming\npm;C:\Users\This pc\AppData\Roaming\Composer\vendor\bin;;C:\laragon\bin\laragon\utils;C:\laragon\bin\mysql\mysql-5.7.33-winx64\bin;C:\laragon\bin\php\php-7.4.19-Win32-vc15-x64;C:\laragon\bin\composer;C:\laragon\bin\apache\httpd-2.4.47-win64-VS16\bin;C:\laragon\bin\redis\redis-x64-3.2.100;C:\laragon\bin\nodejs\node-v14;C:\laragon\bin\nginx\nginx-1.19.10;C:\laragon\bin\notepad++;C:\laragon\bin\telnet;C:\laragon\bin\ngrok;C:\laragon\bin\git\bin;C:\laragon\bin\git\cmd;C:\laragon\bin\git\usr\bin;C:\laragon\bin\git\mingw64\bin;C:\laragon\bin;C:\laragon\usr\bin;C:\laragon\bin\cmder\bin;C:\Python310\Scripts\;C:\Python310\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Users\This pc\AppData\Local\Microsoft\WindowsApps;C:\Users\This pc\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\This pc\AppData\Local\GitHubDesktop\bin;C:\laragon\bin\php\php-7.4.19-Win32-vc15-x64;C:\laragon\bin\php\php-8.1.3-nts-Win32-vs16-x64;C:\Users\This pc\AppData\Roaming\npm;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\share\vim\vim74;C:\laragon\bin\cmder\;
9 verbose lifecycle #~dev: CWD: C:\laragon\www\school
10 silly lifecycle #~dev: Args: [ '/d /s /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> (C:\laragon\bin\nodejs\node-v14\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:315:20)
13 verbose stack at ChildProcess.<anonymous> (C:\laragon\bin\nodejs\node-v14\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:315:20)
13 verbose stack at maybeClose (internal/child_process.js:1048:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid #
15 verbose cwd C:\laragon\www\school
16 verbose Windows_NT 10.0.19044
17 verbose argv "C:\\laragon\\bin\\nodejs\\node-v14\\node.exe" "C:\\laragon\\bin\\nodejs\\node-v14\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
18 verbose node v14.16.1
19 verbose npm v6.14.12
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 ]
Use the new Mix CLI. Inside scripts use...
"scripts": {
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"production": "mix --production"
}

Why can i not run my project in development mode?

When I use npm run serve, I get following message.
PS C:\Users\Jan\Desktop\projektgruppe\Main> npm run serve
> editor#0.1.0 serve C:\Users\Jan\Desktop\projektgruppe\Main
> concurrently "nodemon -L --inspect=0.0.0.0:9001 ./server/index.js" "vue-cli-service build ./src/main.js --mode development --watch"
[0] Error occurred when executing command: nodemon -L --inspect=0.0.0.0:9001 ./server/index.js
[0] Error: spawn cmd.exe ENOENT
[0] at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
[0] at onErrorNT (internal/child_process.js:456:16)
[0] at processTicksAndRejections (internal/process/task_queues.js:81:21)
[1] Error occurred when executing command: vue-cli-service build ./src/main.js --mode development --watch
[1] Error: spawn cmd.exe ENOENT
[1] at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
[1] at onErrorNT (internal/child_process.js:456:16)
[1] at processTicksAndRejections (internal/process/task_queues.js:81:21)
[1] vue-cli-service build ./src/main.js --mode development --watch exited with code -4058
[0] nodemon -L --inspect=0.0.0.0:9001 ./server/index.js exited with code -4058
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! editor#0.1.0 serve: `concurrently "nodemon -L --inspect=0.0.0.0:9001 ./server/index.js" "vue-cli-service build ./src/main.js --mode development --watch"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the editor#0.1.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
and my log file is this
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files\\node\\node.exe',
1 verbose cli 'C:\\Program Files\\node\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'serve'
1 verbose cli ]
2 info using npm#6.13.6
3 info using node#v12.14.1
4 verbose run-script [ 'preserve', 'serve', 'postserve' ]
5 info lifecycle editor#0.1.0~preserve: editor#0.1.0
6 info lifecycle editor#0.1.0~serve: editor#0.1.0
7 verbose lifecycle editor#0.1.0~serve: unsafe-perm in lifecycle true
8 verbose lifecycle editor#0.1.0~serve: PATH: C:\Program Files\node\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Jan\Desktop\projektgruppe\Main\node_modules\.bin;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\node\;C:\Program Files\Git\cmd;C:\Users\Jan\AppData\Local\Microsoft\WindowsApps;C:\Users\Jan\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Jan\AppData\Roaming\npm
9 verbose lifecycle editor#0.1.0~serve: CWD: C:\Users\Jan\Desktop\projektgruppe\Main
10 silly lifecycle editor#0.1.0~serve: Args: [
10 silly lifecycle '/d /s /c',
10 silly lifecycle 'concurrently "nodemon -L --inspect=0.0.0.0:9001 ./server/index.js" "vue-cli-service build ./src/main.js --mode development --watch"'
10 silly lifecycle ]
11 silly lifecycle editor#0.1.0~serve: Returned: code: 1 signal: null
12 info lifecycle editor#0.1.0~serve: Failed to exec serve script
13 verbose stack Error: editor#0.1.0 serve: `concurrently "nodemon -L --inspect=0.0.0.0:9001 ./server/index.js" "vue-cli-service build ./src/main.js --mode development --watch"`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Program Files\node\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:223:5)
13 verbose stack at ChildProcess.<anonymous> (C:\Program Files\node\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:223:5)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid editor#0.1.0
15 verbose cwd C:\Users\Jan\Desktop\projektgruppe\Main
16 verbose Windows_NT 10.0.18363
17 verbose argv "C:\\Program Files\\node\\node.exe" "C:\\Program Files\\node\\node_modules\\npm\\bin\\npm-cli.js" "run" "serve"
18 verbose node v12.14.1
19 verbose npm v6.13.6
20 error code ELIFECYCLE
21 error errno 1
22 error editor#0.1.0 serve: `concurrently "nodemon -L --inspect=0.0.0.0:9001 ./server/index.js" "vue-cli-service build ./src/main.js --mode development --watch"`
22 error Exit status 1
23 error Failed at the editor#0.1.0 serve script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
It always worked, but now not. I tried many times to uninstall node modules. I reinstalled many times node, but I can not find the mistake. I have no Problem, when I just build it and start it. But that is not nice for development.
"start": "node ./server/index.js",
"serve": "concurrently \"nodemon -L --inspect=0.0.0.0:9001 ./server/index.js\" \"vue-cli-service build ./src/main.js --mode development --watch\"",
"build": "vue-cli-service build ./src/main.js",
Would be so glad for any help.
Thanks

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

npm start - npm ERR! missing script: start

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.

What is the error when I set "NODE_ENV=production", how to set environment variable for node script command?

I use webpack 3.1.0, node 9.2.0, command line of windows 10.
Got the error when I run script on package.json.
"scripts": {
"build": "NODE_ENV=production webpack --progress --colors -p",
...
}
I get the errors like below.
13 verbose stack Error: wow_dns#1.0.0 build: `NODE_ENV=production webpack --progress --colors -p`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Users\sheng\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:285:16)
13 verbose stack at EventEmitter.emit (events.js:159:13)
13 verbose stack at ChildProcess.<anonymous> (C:\Users\sheng\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:159:13)
13 verbose stack at maybeClose (internal/child_process.js:943:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
14 verbose pkgid wow_dns#1.0.0
15 verbose cwd F:\wow\wow_dns
16 verbose Windows_NT 10.0.16299
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\sheng\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
But it would be run through, if I delete "NODE_ENV=production" like:
"scripts": {
"build": "webpack --progress --colors -p",
...
}
It will works.
How to setting running environment in with production environment?
In windows, use & to connect two commands, eg:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "SET NODE_ENV=development& webpack serve --progress --color",
"build": "SET NODE_ENV=production& webpack --progress --color",
"serve-old": "webpack-dev-server --watch"
},
Please change
"build": "NODE_ENV=production webpack --progress --colors -p"
to
"build": "set NODE_ENV=production;webpack --progress --colors -p"
or
"build": "NODE_ENV=production;webpack --progress --colors -p"
The problem is that once you finish a command you need to give a semicolon to say that command is over.

Resources