npm error | Error: Cannot find module '#emotion/styled' - node.js

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>

Related

Why is npm deleting my npm folder when trying to install gulp?

I installed node into a "custom" directory:
c:\Apache24\htdocs\node\
Everything is there. When I run:
$ npm install --global gulp-cli
like the docs suggest it appears to install. Then, if I attempt:
$ npm init
it gives me the errors:
Error: Cannot find module 'C:\Apache24\htdocs\node\node_modules\npm\bin\npm-cli.
js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
module.js:549
throw err;
^
Error: Cannot find module 'C:\Apache24\htdocs\node\node_modules\npm\bin\npm-cli.
js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
When I investigate I find that the npm folder ("c:\apache24\htdocs\node\node_modules\npm") is completely gone - erased, no longer there! This also happens to me when just attempting to install plain gulp and not the gulp-cli. Does anyone know why this could be happening?
I'm running windows 8.1.
Here is the package.json:
{
"name": "my-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"npm": "^5.6.0"
},
"devDependencies": {
"gulp": "^3.9.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
have had issue with copy node module directory from one place to another to another before
What i did was
first of all
run npm init
and then npm install --global gulp-cli
that worked for me before

React npm start throwing errors

I am creating a simple HelloWorld application using Node and react. I followed this tutorial when I run
npm start
I get the following error:
> test1#1.0.0 start C:\Users\Saeed\Work\Test1
> webpack-dev-server
The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D
module.js:549
throw err;
^
Error: Cannot find module 'webpack-cli/bin/config-yargs'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\Saeed\Work\Test1\node_modules\webpack-dev-server\bin\webpack-dev-server.js:65:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test1#1.0.0 start: `webpack-dev-server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test1#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
this is my package.json:
{
"name": "test1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"webpack": "^4.16.3",
"webpack-dev-server": "^3.1.5"
}
}
can anyone one point me out to my error? I npm install webpack-cli -D would solve the problem.

Docker compose up 'Exec format error' loading a library

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.

Error: Cannot find module 'mongodb/node_modules/bson'

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

Heroku Deploy Error: Cannot find module './errors/cast'

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.

Resources