I'm developing a multi-module docker nodejs app with docker-compose. There's an issue with the natural node package needed by a module. It seems that it can't exec it. I tried to rebuild it on the fly with a RUN command, but nothing changed.
Here's the log when trying to run docker-compose up:
web_1 | /app/web-server/node_modules/natural/lib/natural/classifiers/classifier.js:32
web_1 | if (e.code !== 'MODULE_NOT_FOUND') throw e;
web_1 | ^
web_1 |
web_1 | Error: Error loading shared library /app/web-server/node_modules/webworker-threads/build/Release/WebWorkerThreads.node: Exec format error
web_1 | at Error (native)
web_1 | at Object.Module._extensions..node (module.js:597:18)
web_1 | at Module.load (module.js:487:32)
web_1 | at tryModuleLoad (module.js:446:12)
web_1 | at Function.Module._load (module.js:438:3)
web_1 | at Module.require (module.js:497:17)
web_1 | at require (internal/module.js:20:19)
web_1 | at bindings (/app/web-server/node_modules/bindings/bindings.js:81:44)
web_1 | at Object.<anonymous> (/app/web-server/node_modules/webworker-threads/index.js:1:105)
web_1 | at Module._compile (module.js:570:32)
web_1 | at Object.Module._extensions..js (module.js:579:10)
web_1 | at Module.load (module.js:487:32)
web_1 | at tryModuleLoad (module.js:446:12)
web_1 | at Function.Module._load (module.js:438:3)
web_1 | at Module.require (module.js:497:17)
web_1 | at require (internal/module.js:20:19)
Here's the package.json:
{
"name": "realaffinities",
"version": "1.0.0",
"description": "",
"main": "server/Server.js",
"keywords": [],
"author": "",
"license": "GPL-3.0",
"dependencies": {
"async": "^2.5.0",
"big-integer": "^1.6.23",
"body-parser": "1.9.0",
"express": "^4.15.3",
"express-validator": "^3.2.1",
"knex": "^0.13.0",
"mysql": "^2.14.1",
"natural": "^0.5.4",
"twit": "^2.2.9",
"url-exists": "^1.0.3",
"nodemon": "^1.11.0"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-express-server": "^0.5.3",
"mocha": "^3.4.2",
"supertest": "^3.0.0",
"bcrypt": "1.0.2"
},
"scripts": {
"test": "mocha web-server/test",
"start": "node server/Server.js"
}
}
My dockerfile:
FROM node:6.11-alpine
EXPOSE 3000
ENV NODE_ENV development
RUN mkdir /app
WORKDIR /app
# add package.json and run npm install before adding the rest of the files
# this way, you only run npm install when package.json changes
ADD /web-server/package.json /app/package.json
RUN apk add --no-cache make gcc g++ python
RUN npm install -g mocha
RUN npm install
I don't know whether it's an issue of this particular node package or a knowledge lack of mine. If I run the same application locally on my mac without docker, it doesn't encounter this problem.
Someone reported same problem in this issue and his case was similar to yours. As discussed in comments, this worked for you, so I am posting this as answer also:
It sounds like it's trying to load a native extension that wasn't
compiled for linux (in the container) -- maybe you previously
installed the extension on OS X and it's trying to load that binary.
If you mean this is a node app, try just removing node_modules and run
npm install again
Fix that worked for you: rm -rf node_modules
Create a .dockerignore file and add /node_modules
None of the answers above worked for me. Switching from bcrypt to bcryptjs was what worked.
docker build --platform linux/amd64 .
Instead of the default arm64, this sometimes works.
Related
I am having an issue running my Node project. This issue did not exist yesterday. I can't think of anything that has changed since other than an update my OS did last night (Ubuntu 20.04).
Stack trace:
[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module '#emotion/styled'
Require stack:
- /home/jake/node_modules/#mui/styled-engine/node/index.js
- /home/jake/node_modules/#mui/system/index.js
- /home/jake/node_modules/#mui/core/node/Popper/Popper.js
- /home/jake/node_modules/#mui/core/node/Popper/index.js
- /home/jake/node_modules/#mui/core/node/index.js
- /home/jake/Documents/Dev/Stock-Informer/models/User.js
- /home/jake/Documents/Dev/Stock-Informer/middleware/passport-config.js
- /home/jake/Documents/Dev/Stock-Informer/server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/home/jake/node_modules/#mui/styled-engine/node/index.js:45:38)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/jake/node_modules/#mui/styled-engine/node/index.js',
'/home/jake/node_modules/#mui/system/index.js',
'/home/jake/node_modules/#mui/core/node/Popper/Popper.js',
'/home/jake/node_modules/#mui/core/node/Popper/index.js',
'/home/jake/node_modules/#mui/core/node/index.js',
'/home/jake/Documents/Dev/Stock-Informer/models/User.js',
'/home/jake/Documents/Dev/Stock-Informer/middleware/passport-config.js',
'/home/jake/Documents/Dev/Stock-Informer/server.js'
]
}
[nodemon] app crashed - waiting for file changes before starting...
It's seems to want a React module, #emotion/style, but my project is not a React project.
package.json:
{
"name": "stock-informer",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-flash": "^0.0.2",
"express-session": "^1.17.2",
"mongoose": "^6.0.13",
"passport": "^0.5.0",
"passport-local": "^1.0.0",
"pug": "^3.0.2"
},
"devDependencies": {
"nodemon": "^2.0.15"
}
}
I tried deleting node_modules and package-lock.json and running npm install, but it didn't change anything. I have also npm install #emotion/styled to see if that would do anything, but it didn't.
I haven't been able find a solution anywhere; any help would be appreciated.
I think I have faced a similar issue before the step that I follow
delete /node_modules
delete package-lock.json
run this command npm cache clean --force or yarn cache clean
npm install or yarn
Hope this will resolve your issue
The build process was excluding the indirect dependencies of my dependencies:
So adding the indirect dependencies as below worked:
import styled from "#emotion/styled";
let MustHave_DummyForSlsBuild = styled.div({
color: "hotpink",
});
<div className="App">
... main code here ...
<MustHave_DummyForSlsBuild></MustHave_DummyForSlsBuild>
</div>
I am trying to execute nodejs code to invoke AWS API using aws-api-gateway-client module. Code workes perfectly in my laptop however when deployed to TEST server which has latest nodejs and aws npm module installed.
var apigClientFactory = require('aws-api-gateway-client')
Path Npm modules are installed:
C:\Program Files\nodejs\node_modules\npm\node_modules
Output
''' internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module 'aws-api-gateway-client'
Require stack:
- C:\Myfolder\agent\scripts\NodeJSAWSConnector\APINetworks.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\ServiceNow\foggydev\agent\scripts\NodeJSAWSConnector\APINetworks.js:8:25)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\MyFolder\\agent\\scripts\\NodeJSAWSConnector\\APINetworks.js'
]
}
'''
Please advise on the above issue.
Update 2:
package.json file has entry
"dependencies": {
"JSONStream": "^1.3.5",
"abbrev": "~1.1.1",
"ansicolors": "~0.3.2",
"ansistyles": "~0.1.3",
"aproba": "^2.0.0",
"archy": "~1.0.0",
"aws-api-gateway-client": "^0.3.3",
"aws-sdk": "^2.656.0",
"bin-links": "^1.1.7",
"bluebird": "^3.5.5",
"byte-size": "^5.0.1",
"cacache": "^12.0.3",
"call-limit": "^1.1.1",
"chownr": "^1.1.4",
"ci-info": "^2.0.0",
"cli-columns": "^3.1.2",
"cli-table3": "^0.5.1",
Also, aws-api-gateway-client is installed at C:\Program Files\nodejs\node_modules\npm\node_modules
Your app is in C:\ServiceNow\foggydev\agent\scripts\NodeJSAWSConnector\APINetworks.js
node_modules are in: C:\Program Files\nodejs\node_modules\npm\node_modules
Seems like You've installed aws-api-gateway-client globally (since You're saying that node_modules folder is in different place)
Steps to check and solve:
1) check package.json file if it exists in dependencies,
2) make sure in Your test server aws-api-gateway-client exists in node_modules folder,
3) do npm i --save aws-api-gateway-client to install it in node_modules folder relative to Your project, which will also add that module to dependencies in package.json
4) deploy to test server again with updated packge.json
I am new to docker and trying to containerise a node app my team have built. Unfortunately, it doesnt seem to build happy.js, a dependency clearly stated in my package.json file.
Here is a copy of my DockerFile:
FROM node:8-alpine
WORKDIR /usr/src/app
ENV UV_THREADPOOL_SIZE 64
COPY cdp-contracts/ ./rpc
COPY cdp-platform/ ./backend
RUN rm -rf backend/node_modules
RUN rm -rf rpc/node_modules
RUN apk add --no-cache --virtual .gyp \
autoconf \
automake \
g++ \
libpng-dev \
libtool \
make \
nasm \
python \
git \
&& npm i -g wait-on concurrently truffle npm#latest \
# && concurrently 'cd rpc; npm init -y ; npm install --save-exact openzeppelin-solidity; npm init -y ; npm i npm#latest -g ' \
# && concurrently 'cd backend; npm init -y ; npm i npm#latest -g ; npm i hapi -g; npm rebuild bcrypt --build-from-source' \
&& concurrently 'cd rpc; npm init -y ; npm install --save-exact openzeppelin-solidity; npm init -y ; npm i npm#latest -g ' \
&& concurrently 'cd backend; npm init -y ; npm i npm#latest -g ; npm i hapi -g; npm rebuild bcrypt --build-from-source' \
&& apk del .gyp
WORKDIR /usr/src/app/rpc
RUN truffle compile --all
WORKDIR /usr/src/app/backend
RUN mkdir -p build/
RUN ln -sf ../../rpc/build/contracts build/contracts
WORKDIR /usr/src/app/backend
EXPOSE 3001
CMD [ "npm", "run", "middleware" ]
The issue is in the backend folder.
Here is a copy of the package.json file copied to this folder:
{
"name": "cdp-platform",
"version": "0.1.0",
"description": "the main platform for CDP",
"main": "server.js",
"private": true,
"scripts": {
"test": "echo ok",
"space{0}": "--- Services ------------------------------------------------",
"middleware": "node ./middleware/server.js",
"middleware:debug": "node --nolazy --inspect-brk=9229 ./middleware/server.js"
},
"repository": {},
"keywords": [],
"author": "",
"license": "",
"dependencies": {
"agentkeepalive": "3.1.0",
"async": "2.5.0",
"axios": "0.18.0",
"bcrypt": "2.0.1",
"bignum": "0.12.5",
"bluebird": "3.5.0",
"boom": "6.0.0",
"csv": "3.1.0",
"csv-parse": "2.5.0",
"documentdb": "1.14.4",
"good": "7.1.0",
"good-console": "6.4.0",
"good-squeeze": "5.0.2",
"greenlock": "2.1.12",
"greenlock-cli": "2.2.6",
"hapi": "16.1.0",
"hapi-auth-jwt2": "7.2.4",
"hapi-authorization": "3.0.3",
"hapi-swagger": "7.9.1",
"http-duplex": "0.0.2",
"inert": "4.2.1",
"is-stream": "1.1.0",
"isemail": "3.0.0",
"joi": "13.0.0",
"jsonwebtoken": "8.1.0",
"lodash": "4.17.10",
"moment": "2.22.1",
"mongodb": "3.0.10",
"pm2": "2.6.1",
"request": "2.80.0",
"scramjet": "4.15.3",
"semver": "5.3.0",
"through": "^2.3.8",
"through2": "^2.0.3",
"toobusy-js": "^0.5.1",
"uuid": "^3.0.1",
"vision": "^4.1.1",
"winston": "^2.3.1",
"xss": "^0.3.3"
},
"devDependencies": {
"babel-eslint": "^8.0.1",
"chai": "^4.1.2",
"eslint": "^4.9.0",
"istanbul": "^0.4.5",
"mocha": "^5.1.1",
"mockery": "^2.0.0",
"nock": "^9.0.9",
"sinon": "^5.0.7"
}
}
Unfortunately, I keep getting this error:
backend_1 | > cdp-platform#0.1.0 middleware /usr/src/app/backend
backend_1 | > node ./middleware/server.js
backend_1 |
backend_1 | module.js:550
backend_1 | throw err;
backend_1 | ^
backend_1 |
backend_1 | Error: Cannot find module 'hapi'
backend_1 | at Function.Module._resolveFilename (module.js:548:15)
backend_1 | at Function.Module._load (module.js:475:25)
backend_1 | at Module.require (module.js:597:17)
backend_1 | at require (internal/module.js:11:18)
backend_1 | at Object.<anonymous> (/usr/src/app/backend/middleware/server.js:2:14)
backend_1 | at Module._compile (module.js:653:30)
backend_1 | at Object.Module._extensions..js (module.js:664:10)
backend_1 | at Module.load (module.js:566:32)
backend_1 | at tryModuleLoad (module.js:506:12)
backend_1 | at Function.Module._load (module.js:498:3)
backend_1 | npm ERR! code ELIFECYCLE
backend_1 | npm ERR! errno 1
backend_1 | npm ERR! cdp-platform#0.1.0 middleware: `node ./middleware/server.js`
backend_1 | npm ERR! Exit status 1
backend_1 | npm ERR!
backend_1 | npm ERR! Failed at the cdp-platform#0.1.0 middleware script.
backend_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
backend_1 | npm WARN Local package.json exists, but node_modules missing, did you mean to install?
backend_1 |
backend_1 | npm ERR! A complete log of this run can be found in:
backend_1 | npm ERR! /root/.npm/_logs/2018-12-04T07_48_39_145Z-debug.log
I would be deeply appreciative of any pointers on this
Your docker file runs npm i hapi -g, so you install hapi globally on the container, but at no point I see you run npm i on your workdir. So I guess your application will not be able to locate any local dependency in node_modules.
I suggest you try adding RUN npm i in your docker file, right after the line WORKDIR /usr/src/app/backend.
I am using node 8.1.2 with mongoose 4.11. On starting the app, I am getting these errors:
D:\express_learn\LAM>node app.js
module.js:487
throw err;
^
Error: Cannot find module 'mongodb/node_modules/bson'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (D:\express_learn\LAM\node_modules\mongoose\lib\drivers\node-mongodb-native\objectid.js:8:16)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
D:\express_learn\LAM>
I tried the following solution from here
npm install node-gyp -g
npm cache clean
rm -rf node_modules
npm install
But still getting the same error.
Here is package.json
{
"name": "learn-about-me",
"private": true,
"scripts": {
"start": "node app"
},
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.6.5",
"connect-flash": "^0.1.1",
"cookie-parser": "^1.3.2",
"ejs": "^1.0.0",
"express": "^4.15.3",
"express-session": "^1.7.6",
"mongoose": "^4.11.0",
"passport": "^0.2.0",
"passport-local": "^1.0.0"
}
}
Here is what I did to resolve the issue
npm cache clean --force
rm -f package-lock.json
node install
I built my app using yeoman angular-fullstack generator and then modified for my own purposes. I built the dist folder to deploy to heroku using yo angular-fullstack:deploy heroku. It creates a new heroku app for me and when I cd into the dist folder and git push heroku master everything works great.
I want to be able to add my existing heroku app to the deployment process for this dist folder so I followed this post How to link a folder with an existing Heroku app. I'm able to then deploy to my own app with a different remote name than heroku.
I keep getting the same error when it starts to run on heroku. I can't figure out why the exact same code runs fine on the app created for me but not my existing app. It's almost like I need to clear the node_modules and push again?
2014-02-21T04:43:51.989439+00:00 app[web.1]: module.js:340
2014-02-21T04:43:51.996351+00:00 app[web.1]: Error: Cannot find module './errors/cast'
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:338:15)
2014-02-21T04:43:51.991555+00:00 app[web.1]: throw err;
2014-02-21T04:43:51.991785+00:00 app[web.1]: ^
2014-02-21T04:43:51.996351+00:00 app[web.1]: at require (module.js:380:17)
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Module.require (module.js:36 4:17)
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Function.Module._load (module.js:280:25)
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Module._compile (module.js:456:26)
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Function.Module._load (module.js:312:12)
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/mongoose/lib/error.js:32:27)
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Module.load (module.js:356:32)
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Object.Module._extensions..js (module.js:474:10)
2014-02-21T04:43:51.996560+00:00 app[web.1]: at Module.require (module.js:364:17)
2014-02-21T04:43:53.457214+00:00 heroku[web.1]: State changed from starting to crashed
Here is my packages.json from the dist folder
{
"name": "myapp",
"version": "1.0.0",
"dependencies": {
"express": "~3.4.3",
"lodash": "~2.4.1",
"mongoose": "~3.5.5",
"mongoose-unique-validator": "~0.3.0",
"connect-mongo": "~0.4.0",
"passport": "latest",
"passport-local": "latest",
"passport-facebook": "latest",
"passport-twitter": "latest",
"passport-google": "latest",
"ejs": "~0.8.4"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "grunt test"
}
}
The issue is almost certainly that you haven't checked in all the files you need. If you can't see the problem in your git repository, try running heroku run bash and using cd, ls, and more to look around what's getting deployed to Heroku and see what is missing.
Your problem is likely that you have require('./errors/cast') but have not checked in a cast file.
Update:
The other likelihood is that you checked in ./errors/Cast on OS X which is case insensitive, but the file can't be found on Linux which is case sensitive.