Trying to run this command: npm run build.
Here is the scripts definition of the package.json file
"scripts": {
"start": "npm run build",
"build": "webpack -d, --devtool && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot",
"build:prod": "webpack -p && cp src/index.html dist/index.html"
},
"keys": [
"reactjs"
],
This is the error been produced regardless I also tried for build in scripts webpack -d, wepack -d --devtool as well webpack -d, --devtool nothing helped. The error shows as
[webpack-cli] Error: Option '-d, --devtool ' argument missing
[webpack-cli] Run 'webpack --help' to see available commands and options
npm ERR! code 2
npm ERR! path /Users/naveed.hasan/Projects/demo/react/fileuplod
npm ERR! command failed
npm ERR! command sh -c webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot
you should configure the devtool option, either in the command line -d eval or in your webpack.config.js file :
module.exports = {
...
devtool: 'eval',
...
};
You have a comma after your -d in your script:
"build": "webpack -d, --devtool
-----------------------------^ there
I'm not a webpack user, but it doesn't look voluntary
Related
in my package.json I have these scripts:
"scripts":
{
"lint": "./node_modules/.bin/eslint src",
"build": "npm run clean && npm run dev && npm run prod",
"tsc": "./node_modules/.bin/tsc",
"dev": "./node_modules/.bin/webpack --config webpack.dev.js",
"prod": "./node_modules/.bin/webpack --config webpack.prod.js",
"clean": "del /q inet-henge*.js* dist",
"watch": "./node_modules/.bin/webpack --config webpack.dev.js --watch",
"postinstall": "copy inet-henge.js \"..\\flask\\customer_topology\\static\""
}
But for some reason postinstall is completely ignored when i run npm run build. When I run it as standalone script, it runs, the file is copied to the new location. Path is correct. What could be the problem, I am on Windows
post<x> runs after <x> so postinstall runs after install and if you want a script to run after build it should be called postbuild See https://docs.npmjs.com/cli/v6/using-npm/scripts for more details.
I have a node.js application which I am trying to run in docker. Here is the package.json file snippet.
"main": "lib/server.js",
"scripts": {
"clean": "cross-env rm -rf dist",
"build": "cross-env babel lib -d dist",
"start": "npm run clean && npm run build && npm run serve",
"serve": "node dist/index.js",
"dev": "cross-env NODE_ENV=development nodemon lib/server.js --exec babel-node",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint --ext .js lib/ scripts/ --ignore-pattern node_modules/"
}
And here is the Dockerfile to build the image
#---- Base Node------
FROM node:10.15.1-alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package*.json ./
COPY lib ./lib
RUN npm install --only=production && npm run build
EXPOSE 4201
CMD ["npm", "run", "serve"]
I get the following error when I try to run the image. Here is the screenshot of the error.
The node and npm version are the same on my machine and the base image that I am using to build my image.
When I run the same command locally in my machine it works
Here is the exact command that I am running on my machine and it works.
npm install --only=production
npm run build
npm run serve
Am I doing something wrong here ? Any help is appreciated.
You are using ES6 imports
import x from package
In order to do that, you should have Babel package installed, otherwise it won't know how to import that file
I have the following script in my package.json:
"scripts": {
"dev": "nodemon server --exec babel-node --presets es2015,stage-2",
"build": "babel ./server -d ./dist",
"start": "node ./dist",
"heroku-postbuild": "cd react-ui/ && npm install && npm install --only=dev --no-shrinkwrap && npm run build"
},
On deploying to Heroku I get the following error
Error: Cannot find module '/app/dist'
On local npm run dev, npm run build, and npm run start work fine.
Where is it getting the /app folder? How to fix this?
Thanks
Matloob
You should build your app npm run build before deploy to heroku. It will run heroku-postbuild first then start your app.
Try this :
"start:heroku": "node dist/YOUR-APP-NAME/server/main.js",
Using NPM 5, run npm test:
"scripts": {
"build": "babel src -d dist",
"test": "npm run build; mocha --require 'babel-polyfill' --compilers js:babel-register './tests/**/*.spec.js'"
},
I get this error:
npm ERR! missing script: build;
Using NPM 2 without any problem
If I replace npm run build; => babel src -d dist, I got this error:
mocha doesn't exist. './tests/**/*.spec.js' doesn't exist
but mocha is installed and tests folder exixts.
Tried to check your error, and created this code:
{
...
"scripts": {
"build": "echo 'building'",
"test": "npm run build && echo 'testing'"
},
...
}
then I simply ran:
npm test
and this was my output:
building
testing
npm - 5.0.3
So try maybe replacing ";" with "&&" in npm test
These scripts have two dashes expression. (e.g. server:dev -- --inline --hot)
"server:dev:hmr": "npm run server:dev -- --inline --hot",
"server:dev": "npm run webpack-dev-server -- --config config/webpack.dev.js --open --progress --profile --watch --content-base src/",
"server:prod": "http-server dist -c-1 --cors",
"server:prod:ci": "http-server dist -p 3000 -c-1 --cors",
"server": "npm run server:dev",
"start:hmr": "npm run server:dev:hmr",
"start": "concurrently \"npm run server:dev\" \"nodemon --watch server server-start.js\" ",
What is the meaning of these two dashes?
And what's the name of this expression?
It's a way to pass arguments to npm-run-script.
npm run <command> [-- <args>]
From the docs:
As of npm#2.0.0, you can use custom arguments when executing scripts. The special option -- is used by getopt to delimit the end of the options. npm will pass all the arguments after the -- directly to your script:
npm run test -- --grep="pattern"