npm dependency in cloud functions - node.js

I've defined my npm dependency in the package.json file:
{
"name": "phash-hamming",
"version": "0.0.1",
"dependencies": {
"phash-image": "3.5.0"
}
}
In my index.js the first line causes an error:
var phash = require('phash-image');
The Error:
Build failed: exit status 1
phash-image#3.5.0 install /workspace/node_modules/phash-image
node-gyp rebuild
/bin/sh: 1: pkg-config: not found gyp: Call to 'pkg-config
--libs-only-L --libs-only-other pHash' returned exit status 127 while in binding.gyp. while trying to load binding.gyp gyp ERR! configure
error gyp ERR! stack Error: gyp failed with exit code: 1 gyp ERR!
stack at ChildProcess.onCpExit
(/nodejs/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:305:16)
gyp ERR! stack at emitTwo (events.js:106:13) gyp ERR! stack at
ChildProcess.emit (events.js:191:7) gyp ERR! stack at
Process.ChildProcess._handle.onexit (internal/child_process.js:219:12)
gyp ERR! System Linux 4.4.0-116-generic gyp ERR! command
"/nodejs/bin/node"
"/nodejs/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js"
"rebuild" gyp ERR! cwd /workspace/node_modules/phash-image gyp ERR!
node -v v6.11.5 gyp ERR! node-gyp -v v3.4.0 gyp ERR! not ok

https://github.com/mgmtio/phash-image
Read the Installation section.
phash-image depends on CImg, pHash, ImageMagicK.
Do you have install one of above?

The following worked for me:
1.Load the phash-image library from inside the function you are calling.
2.Use the package.json from the phash-image repo.
Your index.js:
exports.helloWorld = (req, res) => {
var phash = require('phash-image');
};
Your package.json:
{
"name": "phash-image",
"version": "3.5.0",
"description": "phash for images",
"repository": "mgmtio/phash-image",
"devDependencies": {
"bluebird": "^3.1.5",
"hamming-distance": "^1.0.0",
"istanbul": "^0.4.2",
"mocha": "^3.0.0",
"node-gyp": "^3.3.0"
},
"script": {
"preinstall": "node-gyp configure build",
"preuninstall": "rm -rf build/*"
},
"scripts": {
"build": "node-gyp configure build",
"test": "npm run build && mocha",
"test-cov": "npm run build && istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot",
"test-travis": "npm run build && istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot"
},
"keywords": [
"pHash",
"phash",
"libpHash",
"native",
"binding",
"addon"
],
"author": "Aaron Marasco <agm257#mail.missouri.edu>",
"contributors": [
"Aaron Marasco <agm257#mail.missouri.edu>",
"Taeho Kim <xissysnd#gmail.com>",
"Jeremy Dowell <jeremy#codevinsky.com>",
"Rod Vagg <r#va.gg> (https://github.com/rvagg)",
"Jonathan Ong <me#jongleberry.com> (https://github.com/jonathanong)"
],
"dependencies": {
"any-promise": "^1.1.0",
"nan": "^2.0.5"
},
"license": "MIT"
}

Related

Postinstall of module is executed before postinstall of sub-module

Edit:
I'm asking how to install it from GitHub, not npm, that the question.
In case you want to know why: I'm working on some private projects and don't what t publish the code. This leads to the code being in a private repository, not published on npm.
Original post:
Trying to install a module from GitHub (it is in typescript, thus I need a compilation script [postinstall]). It seems to fail because one of the module dependencies is also on GitHub, and that postinstall script is not waited on by the current postinstall script.
Old GitHub issue that sounds related: https://github.com/npm/npm/issues/5001
Yes, like the issue, I also use the same dependency in the main project as the module does.
Program
Version
node
v16.1.0
npm
7.11.2
npm info run newton#1.0.1 postinstall node_modules/newton tsc -d -p .
npm info run nodemon#2.0.7 postinstall node_modules/nodemon node bin/postinstall || exit 0
npm info run rendery#2.0.0 postinstall node_modules/rendery tsc -d -p .
npm info run nodemon#2.0.7 postinstall { code: 0, signal: null }
npm timing build:run:postinstall:node_modules/nodemon Completed in 157ms
npm info run newton#1.0.1 postinstall { code: 0, signal: null }
npm timing build:run:postinstall:node_modules/newton Completed in 2409ms
npm info run rendery#2.0.0 postinstall { code: 2, signal: null }
npm timing reify:rollback:createSparse Completed in 2864ms
npm timing reify:rollback:retireShallow Completed in 0ms
npm timing command:install Completed in 47807ms
npm verb stack Error: command failed
npm verb stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\#npmcli\promise-spawn\index.js:64:27)
npm verb stack at ChildProcess.emit (node:events:365:28)
npm verb stack at maybeClose (node:internal/child_process:1067:16)
npm verb stack at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
npm verb pkgid rendery#2.0.0
npm verb cwd C:\Users\Elias\git\natrias
npm verb Windows_NT 10.0.19043
npm verb argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "i" "--verbose" "--force"
npm verb node v16.1.0
npm verb npm v7.11.2
npm ERR! code 2
npm ERR! path C:\Users\Elias\git\natrias\node_modules\rendery
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c tsc -d -p .
npm ERR! src/2d/CanvasRenderyContext2D.ts(1,29): error TS2307: Cannot find module 'newton/2d/ReadonlyVector2' or its corresponding type declarations.
npm ERR! src/2d/CanvasRenderyContext2D.ts(2,21): error TS2307: Cannot find module 'newton/2d/Vector2' or its corresponding type declarations.
npm ERR! src/2d/ReadonlyRenderyContext2D.ts(1,29): error TS2307: Cannot find module 'newton/2d/ReadonlyVector2' or its corresponding type declarations.
npm ERR! src/2d/RenderyContext2D.ts(1,29): error TS2307: Cannot find module 'newton/2d/ReadonlyVector2' or its corresponding type declarations.
npm verb exit 2
npm timing npm Completed in 48318ms
npm verb code 2
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Elias\AppData\Local\npm-cache\_logs\2021-05-12T16_19_34_975Z-debug.log
Note that rendery postinstall starts before newton postinstall completes.
Newton package.json
{
"name": "newton",
"version": "1.0.1",
"description": "",
"scripts": {
"lint": "eslint '*/**/*.ts'",
"lint:fix": "eslint '*/**/*.ts' --fix",
"postinstall": "tsc -d -p .",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^4.22.0",
"#typescript-eslint/parser": "^4.22.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0"
},
"dependencies": {
"typescript": "^4.2.4"
}
}
Rendery package.json
{
"name": "rendery",
"version": "2.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint '*/**/*.ts'",
"lint:fix": "eslint '*/**/*.ts' --fix",
"postinstall": "tsc -d -p ."
},
"keywords": [],
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^4.22.0",
"#typescript-eslint/parser": "^4.22.0",
"eslint": "^7.25.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-typescript-sort-keys": "^1.6.0"
},
"dependencies": {
"newton": "github:Elias-Graf/newton#main",
"typescript": "^4.2.4"
}
}
It's not a good practice to publish unbuilt packages. I recommend changing the postinstall script into a prepare script so it builds the package before publishing it.
{
"name": "newton",
"version": "1.0.1",
"description": "",
"scripts": {
"lint": "eslint '*/**/*.ts'",
"lint:fix": "eslint '*/**/*.ts' --fix",
"prepare": "tsc -d -p .",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^4.22.0",
"#typescript-eslint/parser": "^4.22.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0"
},
"dependencies": {
"typescript": "^4.2.4"
}
}
{
"name": "rendery",
"version": "2.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint '*/**/*.ts'",
"lint:fix": "eslint '*/**/*.ts' --fix",
"prepare": "tsc -d -p ."
},
"keywords": [],
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^4.22.0",
"#typescript-eslint/parser": "^4.22.0",
"eslint": "^7.25.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-typescript-sort-keys": "^1.6.0"
},
"dependencies": {
"newton": "github:Elias-Graf/newton#main",
"typescript": "^4.2.4"
}
}
This would fix your issue.

NPM unable to find package.json file in React App

I've just gone to rerun my React app that I've been working on over the last few weeks and get this
C:\Users\matth\Documents\GitHub\LoveFoods-App>npm start
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\matth\Documents\GitHub\LoveFoods-App\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\matth\Documents\GitHub\LoveFoods-App\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\matth\AppData\Roaming\npm-cache\_logs\2020-07-09T22_47_25_246Z-debug.log
Log for the error showing
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:\\Users\\matth\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'start'
1 verbose cli ]
2 info using npm#6.14.5
3 info using node#v12.16.3
4 verbose stack Error: ENOENT: no such file or directory, open 'C:\Users\matth\Documents\GitHub\LoveFoods-App\package.json'
5 verbose cwd C:\Users\matth\Documents\GitHub\LoveFoods-App
6 verbose Windows_NT 10.0.18362
7 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\matth\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
8 verbose node v12.16.3
9 verbose npm v6.14.5
10 error code ENOENT
11 error syscall open
12 error path C:\Users\matth\Documents\GitHub\LoveFoods-App\package.json
13 error errno -4058
14 error enoent ENOENT: no such file or directory, open 'C:\Users\matth\Documents\GitHub\LoveFoods-App\package.json'
15 error enoent This is related to npm not being able to find a file.
16 verbose exit [ -4058, true ]
package.json as below
{
"name": "lovefoods-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#auth0/auth0-react": "^1.0.0",
"#auth0/auth0-spa-js": "^1.10.0",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"firebase": "^7.15.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
The thing is, that the package.json file is sitting in the folder and hasn't been moved at all since I last added to the application.
Anyone have any solutions that can help out at all? I've looked everywhere and can't seem to find anything that works.
Thanks!

Receiving an npm error after running "npm run build" : npm ERR! code ELIFECYCLE npm ERR! errno 2

I am having difficulty getting to the bottom of this npm error I am receiving after my npm run build script executes. The error in the terminal is as follows:
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! vincent-site#1.0.0 build: `webpack --mode production`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the vincent-site#1.0.0 build 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! /Users/vincentcastelli/.npm/_logs/2018-11-10T20_27_41_388Z-debug.
Not very descriptive. I am using the most recent npm version at the time of writing this (6.4.1) and the most recent node (11.1.0). I am also using Babel 7 with Webpack 4 for my compiling. I have tried a few things so far.
I have tried the following steps when using both the recent version of npm/node and older versions:
npm cache clean --force
delete node_modules by $ rm -rf node_modules folder
npm install
Still receiving the error.
My log output:
0 info it worked if it ends with ok
1 verbose cli [ '/Users/vincentcastelli/.nvm/versions/node/v11.1.0/bin/node',
1 verbose cli '/Users/vincentcastelli/.nvm/versions/node/v11.1.0/bin/npm',
1 verbose cli 'run',
1 verbose cli 'build' ]
2 info using npm#6.4.1
3 info using node#v11.1.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle vincent-site#1.0.0~prebuild: vincent-site#1.0.0
6 info lifecycle vincent-site#1.0.0~build: vincent-site#1.0.0
7 verbose lifecycle vincent-site#1.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle vincent-site#1.0.0~build: PATH: /Users/vincentcastelli/.nvm/versions/node/v11.1.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/vincentcastelli/Documents/02_Projects/vincent-site/node_modules/.bin:/Users/vincentcastelli/.nvm/versions/node/v11.1.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
9 verbose lifecycle vincent-site#1.0.0~build: CWD: /Users/vincentcastelli/Documents/02_Projects/vincent-site
10 silly lifecycle vincent-site#1.0.0~build: Args: [ '-c', 'webpack --mode production' ]
11 silly lifecycle vincent-site#1.0.0~build: Returned: code: 2 signal: null
12 info lifecycle vincent-site#1.0.0~build: Failed to exec build script
13 verbose stack Error: vincent-site#1.0.0 build: `webpack --mode production`
13 verbose stack Exit status 2
13 verbose stack at EventEmitter.<anonymous> (/Users/vincentcastelli/.nvm/versions/node/v11.1.0/lib/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> (/Users/vincentcastelli/.nvm/versions/node/v11.1.0/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:970:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:257:5)
14 verbose pkgid vincent-site#1.0.0
15 verbose cwd /Users/vincentcastelli/Documents/02_Projects/vincent-site
16 verbose Darwin 18.0.0
17 verbose argv "/Users/vincentcastelli/.nvm/versions/node/v11.1.0/bin/node" "/Users/vincentcastelli/.nvm/versions/node/v11.1.0/bin/npm" "run" "build"
18 verbose node v11.1.0
19 verbose npm v6.4.1
20 error code ELIFECYCLE
21 error errno 2
22 error vincent-site#1.0.0 build: `webpack --mode production`
22 error Exit status 2
23 error Failed at the vincent-site#1.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]
My package.json:
}
"scripts": {
"start": "node server.js",
"build": "webpack --mode production"
},
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.3",
"prop-types": "^15.6.1",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-router-dom": "^4.3.1"
},
"engines": {
"node": "10.13.0"
},
"babel": {
"presets": [
"#babel/preset-env",
"#babel/react"
],
"plugins": [
"#babel/proposal-class-properties"
]
},
"eslintConfig": {
"extends": "airbnb",
"parser": "babel-eslint"
},
"devDependencies": {
"#babel/core": "^7.1.5",
"#babel/plugin-proposal-class-properties": "^7.1.0",
"#babel/plugin-proposal-object-rest-spread": "^7.0.0",
"#babel/preset-env": "^7.1.5",
"#babel/preset-react": "^7.0.0",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.4",
"css-loader": "^1.0.1",
"eslint": "^5.9.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-loader": "^2.1.1",
"eslint-plugin-ejs": "0.0.2",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"file-loader": "^2.0.0",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"node-sass": "^4.10.0",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"webpack": "^4.25.1",
"webpack-cli": "^3.1.2"
}
}
My webpack config:
const path = require('path');
const HtmlWebPackPlugin = require("html-webpack-plugin");
const distDir = path.join(__dirname, '/dist');
const srcDir = path.join(__dirname, '/src');
module.exports = {
entry: `${srcDir}/index.jsx`,
output: {
path: `${distDir}`,
filename: 'bundle.js',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
use: ['babel-loader', 'eslint-loader'],
},
{
test: /\.html$/,
use: [
{
loader: "html-loader"
}
]
},
{
test: /\.scss$/,
use: [
"style-loader",
"css-loader",
"sass-loader"
]
},
{
test: /\.(jpg|mp4|ogv|webm)$/,
use: 'file-loader',
},
],
},
plugins: [
new HtmlWebPackPlugin({
template: "./dist/index.html",
filename: "./index.html"
})
],
resolve: { extensions: ['*', '.js', '.jsx'] },
devtool: 'cheap-eval-source-map',
};
I feel that the issue stems from a package versioning incompatibility but isolating the issue has been challenging. Thank you in advance for the assistance!
Step 1: $ npm cache clean --force
Step 2: delete node_modules folder
step 3: delete package-lock.json file
Step 4: npm install
To start again, $ npm run start or npm run build
This worked for me. Hopes it works for you.
I found out my CI/CD pipeline on Semaphore was running on a virtual machine without enough memory, thus it was failing and throwing me the error 😭
Check your memory wherever you are running that command

npm install fails while dependency build

I am running npm install for below package.json project file:
{
"name": "tradesync",
"version": "1.0.0",
"description": "",
"main": "consumer.js",
"dependencies": {
"async": "^2.6.1",
"avsc": "^5.1.1",
"cron": "^1.3.0",
"deepstream.io-client-js": "^2.3.0",
"firebase-admin": "^5.5.1",
"got": "^8.3.1",
"kafka-avro": "^0.8.0",
"mysql": "^2.15.0",
"node-avro-io": "^1.0.1",
"node-cron": "^1.2.1",
"node-rdkafka": "^2.2.2",
"orderbook-engine": "^1.1.2",
"requestretry": "^1.12.2",
"schema-registry": "^1.17.0",
"slack-node": "^0.1.8",
"socket.io-client": "^2.0.4",
"tedious": "^2.1.5",
"tedious-connection-pool": "^1.0.5",
"underscore": "^1.8.3",
"winston": "^2.4.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"ordermatcher",
"mywallet"
],
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": ""
}
It's breaking and showing error logs at v8 functions, here is the partial snapshot of error logs
/home/local/mywallet/suresh.prajapati/.node-gyp/10.6.0/include/node/v8.h:3914:44: note: candidate expects 1 argument, 2 provided
../src/Int64.cc: In static member function ‘static Nan::NAN_METHOD_RETURN_TYPE Int64::Sub(Nan::NAN_METHOD_ARGS_TYPE)’:
../src/Int64.cc:361:53: error: no matching function for call to ‘v8::Function::NewInstance(int, v8::Local<v8::Value> [2])’
Local<Object> instance = cons->NewInstance(2, argv);
^
In file included from /home/local/mywallet/suresh.prajapati/.node-gyp/10.6.0/include/node/node.h:63:0,
from ../src/Int64.cc:5:
/home/local/mywallet/suresh.prajapati/.node-gyp/10.6.0/include/node/v8.h:3911:44: note: candidate: v8::MaybeLocal<v8::Object> v8::Function::NewInstance(v8::Local<v8::Context>, int, v8::Local<v8::Value>*) const
V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
^
/home/local/mywallet/suresh.prajapati/.node-gyp/10.6.0/include/node/v8.h:3911:44: note: candidate expects 3 arguments, 2 provided
/home/local/mywallet/suresh.prajapati/.node-gyp/10.6.0/include/node/v8.h:3914:44: note: candidate: v8::MaybeLocal<v8::Object> v8::Function::NewInstance(v8::Local<v8::Context>) const
V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
^
/home/local/mywallet/suresh.prajapati/.node-gyp/10.6.0/include/node/v8.h:3914:44: note: candidate expects 1 argument, 2 provided
Int64.target.mk:102: recipe for target 'Release/obj.target/Int64/src/Int64.o' failed
make: *** [Release/obj.target/Int64/src/Int64.o] Error 1
make: Leaving directory '/home/local/mywallet/suresh.prajapati/projects/tradesync/node_modules/int64-native/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
gyp ERR! System Linux 4.13.0-45-generic
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build"
gyp ERR! cwd /home/local/mywallet/suresh.prajapati/projects/tradesync/node_modules/int64-native
gyp ERR! node -v v10.6.0
gyp ERR! node-gyp -v v3.7.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! int64-native#0.4.0 install: `node-gyp configure && node-gyp build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the int64-native#0.4.0 install script.
Here is sys version info
node - v10.6.0
npm - 6.1.0
Python - 2.7.12
Searched on the internet but none of them actually helped. Ready to try out anything which can solve above build fail problem.
Tons of thanks in advance.
This can be a Node issue. Try to install latest LTS version https://nodejs.org/en/download/ .
Should fix it.

npm run build / deploy error on windows

I am trying to compile files with webpack and npm for my reactJS applciation.
When I run npm start, it all goes well.
When I run npm run deploy or npm run build it does not work under a windows environment. It does work under a linux environment.
Does someone have an idea why ?
My files :
package.json
{
"license": "UNLICENSED",
"private": true,
"version": "1.0.0",
"webPath": "web/",
"nodePath": "node_modules/",
"devDependencies": {
"autoprefixer": "^6.3.1",
"exports-loader": "^0.6.2",
"grunt": "^0.4.5",
"grunt-autoprefixer": "^3.0.3",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-cssmin": "^0.14.0",
"grunt-contrib-less": "^1.1.0",
"grunt-contrib-uglify": "^0.11.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-css-url-rewrite": "^0.3.5",
"grunt-cssjoin": "^0.3.0",
"grunt-postcss": "^0.7.1",
"imports-loader": "^0.6.5",
"matchdep": "^1.0.0",
"redux-devtools": "^3.0.2",
"redux-devtools-dock-monitor": "^1.0.1",
"redux-devtools-log-monitor": "^1.0.4",
"webpack-shell-plugin": "^0.4.2"
},
"repository": {
"type": "git",
"url": ""
},
"dependencies": {
"babel-core": "^6.4.0",
"babel-loader": "^6.2.1",
"babel-plugin-transform-runtime": "^6.4.3",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"babel-runtime": "^6.3.19",
"grunt-postcss": "^0.7.1",
"history": "^1.17.0",
"i18next": "^2.5.1",
"isomorphic-fetch": "^2.2.1",
"lodash": "^4.11.1",
"radium": "^0.16.2",
"rc-switch": "^1.4.2",
"react": "^0.14.6",
"react-dom": "^0.14.6",
"react-hot-loader": "^1.3.0",
"react-redux": "^4.1.2",
"react-router": "^1.0.3",
"react-router-redux": "^3.0.0",
"redux": "^3.1.6",
"redux-thunk": "^2.1.0",
"selfupdate": "^1.1.0",
"webpack": "^1.12.11",
"webpack-dev-server": "^1.14.1",
"whatwg-fetch": "^0.11.0"
},
"scripts": {
"start": "node webpack.dev-server.js",
"build": "webpack",
"deploy": "NODE_ENV=production webpack -p --config webpack.production.config.js"
}
}
webpack.config.js
var path = require('path');
var webpack = require('webpack');
var node_modules_dir = path.join(__dirname, 'node_modules');
var devFlagPlugin = new webpack.DefinePlugin({
__DEV__: JSON.stringify(JSON.parse(process.env.DEBUG || 'false'))
});
console.log(__dirname);
var config = {
entry: [
'babel-polyfill',
'webpack-dev-server/client?http://127.0.0.1:3000',
'webpack/hot/only-dev-server',
'./app/Resources/react/app.js'
],
output: {
path: path.join(__dirname, 'web/js'),
filename: 'bundle.js',
publicPath: 'http://127.0.0.1:3000/static/'
},
debug: true,
devtool: 'eval',
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
devFlagPlugin
],
module: {
loaders: [
{
loaders: ["react-hot","babel-loader?plugins=transform-runtime&presets[]=es2015&presets[]=stage-0&presets[]=react"],
test: /\.js$/,
include: path.join(__dirname, 'app/Resources/react')
}
]
}
};
module.exports = config;
/*
new webpack.ProvidePlugin({
'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch'
})
*/
webpack.dev-server.js
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
quiet: false,
noInfo: false,
contentBase: "./assets"
}).listen(3000, 'localhost', function (err, result) {
if (err) {
console.log(err);
}
console.log('Listening at localhost:3000');
});
webpack.production.config.js
var path = require('path');
var node_modules_dir = path.resolve(__dirname, 'node_modules');
var config = {
entry: [
'babel-polyfill',
'./app/Resources/react/app.js'
],
debug: false,
output: {
path: path.join(__dirname, 'web/js'),
filename: 'bundle.js'
},
module: {
loaders: [
{
loaders: ["babel-loader?plugins=transform-runtime&presets[]=es2015&presets[]=stage-0&presets[]=react"],
test: /\.js$/,
include: path.join(__dirname, 'app/Resources/react')
}
]
},
plugins: []
};
module.exports = config;
I get the following error with npm run build
Microsoft Windows [Version 10.0.10586] (c) 2015 Microsoft Corporation.
All rights reserved.
D:\Divers\Programmation\Web\foodmeup.dev>npm run build
FoodMeUp#1.0.0 build D:\Divers\Programmation\Web\foodmeup.dev
webpack
D:\Divers\Programmation\Web\foodmeup.dev Hash: 9cb8c898ada89430aa7c
Version: webpack 1.13.1 Time: 3353ms [0] multi main 64 bytes {0}
[built]
+ 739 hidden modules
ERROR in ./app/Resources/react/components/subscription/total.js Module
not found: Error: Cannot resolve module 'lodash' in
D:\Divers\Programmation\Web\foodmeup.dev\app\Resources\react\components\subscription
# ./app/Resources/react/components/subscription/total.js 19:8-25
my total.js file :
import React from 'react';
import { connect } from 'react-redux';
import { updateSubscription } from '../../actions/subscription';
var _ = require('lodash');
...
I get the following error when I launch npm run deploy
D:\Divers\Programmation\Web\foodmeup.dev>npm run deploy
FoodMeUp#1.0.0 deploy D:\Divers\Programmation\Web\foodmeup.dev
NODE_ENV=production webpack -p --config webpack.production.config.js
'NODE_ENV' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Windows_NT 10.0.10586 npm ERR! argv
"C:\Development\nodejs\node.exe"
"C:\Development\nodejs\node_modules\npm\bin\npm-cli.js" "run"
"deploy" npm ERR! node v6.2.2 npm ERR! npm v3.9.5 npm ERR! code
ELIFECYCLE npm ERR! FoodMeUp#1.0.0 deploy: NODE_ENV=production
webpack -p --config webpack.production.config.js npm ERR! Exit status
1 npm ERR! npm ERR! Failed at the FoodMeUp#1.0.0 deploy script
'NODE_ENV=production webpack -p --config
webpack.production.config.js'. npm ERR! Make sure you have the latest
version of node.js and npm installed. npm ERR! If you do, this is most
likely a problem with the FoodMeUp package, npm ERR! not with npm
itself. npm ERR! Tell the author that this fails on your system: npm
ERR! NODE_ENV=production webpack -p --config
webpack.production.config.js npm ERR! You can get information on how
to open an issue for this project with: npm ERR! npm bugs FoodMeUp
npm ERR! Or if that isn't available, you can get their info via: npm
ERR! npm owner ls FoodMeUp npm ERR! There is likely additional
logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! D:\Divers\Programmation\Web\foodmeup.dev\npm-debug.log
and my npm-debug.log
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Development\\nodejs\\node.exe',
1 verbose cli 'C:\\Development\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'deploy' ]
2 info using npm#3.9.5
3 info using node#v6.2.2
4 verbose run-script [ 'predeploy', 'deploy', 'postdeploy' ]
5 info lifecycle FoodMeUp#1.0.0~predeploy: FoodMeUp#1.0.0
6 silly lifecycle FoodMeUp#1.0.0~predeploy: no script for predeploy, continuing
7 info lifecycle FoodMeUp#1.0.0~deploy: FoodMeUp#1.0.0
8 verbose lifecycle FoodMeUp#1.0.0~deploy: unsafe-perm in lifecycle true
9 verbose lifecycle FoodMeUp#1.0.0~deploy: PATH: C:\Development\nodejs\node_modules\npm\bin\node-gyp-bin;D:\Divers\Programmation\Web\foodmeup.dev\node_modules\.bin;C:\Development\nodejs;C:\img;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Development\Git\cmd;C:\Program Files (x86)\Windows Live\Shared;C:\Development\wamp\bin\php\php7.0.0;C:\Net Generation\FireFox\;C:\Development\wamp\bin\mysql\mysql5.7.9\bin;C:\Program Files (x86)\Skype\Phone\;D:\Divers\Programmation\Web\foodmeup.dev\node_modules\typescript\bin;C:\Development\nodejs\;C:\Development\ruby\bin;C:\Development\wamp\bin\php\php7.0.0;C:\Development\wamp\bin\mysql\mysql5.7.9\bin;D:\Divers\Programmation\Web\foodmeup.dev\node_modules\typescript\bin;C:\img;C:\Users\Sébastien\AppData\Roaming\npm
10 verbose lifecycle FoodMeUp#1.0.0~deploy: CWD: D:\Divers\Programmation\Web\foodmeup.dev
11 silly lifecycle FoodMeUp#1.0.0~deploy: Args: [ '/d /s /c',
11 silly lifecycle 'NODE_ENV=production webpack -p --config webpack.production.config.js' ]
12 silly lifecycle FoodMeUp#1.0.0~deploy: Returned: code: 1 signal: null
13 info lifecycle FoodMeUp#1.0.0~deploy: Failed to exec deploy script
14 verbose stack Error: FoodMeUp#1.0.0 deploy: `NODE_ENV=production webpack -p --config webpack.production.config.js`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (C:\Development\nodejs\node_modules\npm\lib\utils\lifecycle.js:245:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (C:\Development\nodejs\node_modules\npm\lib\utils\spawn.js:24:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:852:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
15 verbose pkgid FoodMeUp#1.0.0
16 verbose cwd D:\Divers\Programmation\Web\foodmeup.dev
17 error Windows_NT 10.0.10586
18 error argv "C:\\Development\\nodejs\\node.exe" "C:\\Development\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "deploy"
19 error node v6.2.2
20 error npm v3.9.5
21 error code ELIFECYCLE
22 error FoodMeUp#1.0.0 deploy: `NODE_ENV=production webpack -p --config webpack.production.config.js`
22 error Exit status 1
23 error Failed at the FoodMeUp#1.0.0 deploy script 'NODE_ENV=production webpack -p --config webpack.production.config.js'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the FoodMeUp package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error NODE_ENV=production webpack -p --config webpack.production.config.js
23 error You can get information on how to open an issue for this project with:
23 error npm bugs FoodMeUp
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls FoodMeUp
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
It looks like the configuration file is not 100% correct. See details below:
need to import 'webpack' mobile before using it (webpack.config.js),
i.e., const webpack = require('webpack');
need to import path module before using it (webpack.config.js),
i.e., const path = require('path');
devFlagPlugin is not defined
also exclude the node_modules directory in the loader
module: {
loaders: [
{
....
exclude: path.resolve(__dirname, 'node_modules/')
}
]
}
I think you have two different problems.
Lodash is missing?
Now, I'm not an expert in Webpack so somebody may point out something obvious that I don't see...but...when you say it doesn't work under Windows, have you tried it on multiple Windows systems?
If this issue is only on one system or it's a PITA to get onto a second box or whatever, try:
Delete the node_modules directory
Execute npm cache clean to be sure you'll start fresh when you reinstall
Re-install with npm i --verbose > npm-install-log.txt
If the install still doesn't work, you'll have an install log to review to see if something is failing to compile or there's some other wacky error that may not be visible after install.
NODE_ENV on Windows
The NODE_ENV=production <commands> syntax is a *nix thing but not a Windows/DOS thing.
In this case, you may find it easier to create a .bat file for this where you set the variable on the first line and call the command on the second. However, this won't work on *nix platforms so....maybe:
Create two scripts and two entries in package.json, one for each OS. If it's a simple project that's mostly maintained by hand, that's probably cool.
Create a deploy.js script, executed by node, that sets the NODE_ENV variable, calls webpack via the node api to do the work. This should be OS independent and is a single script...
You can set environment variables in a cross-platform manner by using cross-env:
"deploy": "cross-env NODE_ENV=production webpack -p --config webpack.production.config.js"

Resources