I am new to coding and would appreciate some help with this I get the following error when I try to run my react app: npm run start
Failed to compile.
Loading PostCSS "postcss-normalize" plugin failed: Cannot find module 'postcss-normalize'
Require stack:
/Users/abc/node_modules/postcss-loader/dist/utils.js
/Users/abc/node_modules/postcss-loader/dist/index.js
/Users/abc/node_modules/postcss-loader/dist/cjs.js
/Users/abc/node_modules/loader-runner/lib/loadLoader.js
/Users/abc/node_modules/loader-runner/lib/LoaderRunner.js
/Users/abc/node_modules/webpack/lib/NormalModule.js
/Users/abc/node_modules/webpack-manifest-plugin/dist/index.js
/Users/abc/node_modules/react-scripts/config/webpack.config.js
/Users/abc/node_modules/react-scripts/scripts/start.js
(#/Users/abc/node_modules/bootstrap/dist/css/bootstrap.css)
ERROR in ./node_modules/bootstrap/dist/css/bootstrap.css (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[2]!./node_modules/source-map-loader/dist/cjs.js!./node_modules/bootstrap/dist/css/bootstrap.css)
./node_modules/bootstrap/dist/css/bootstrap.css (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[2]!./node_modules/source-map-loader/dist/cjs.js!./node_modules/bootstrap/dist/css/bootstrap.css)
Module Error (from ./node_modules/postcss-loader/dist/cjs.js):
Loading PostCSS "postcss-normalize" plugin failed: Cannot find module 'postcss-normalize'
Require stack:
/Users/abc/node_modules/postcss-loader/dist/utils.js
/Users/abc/node_modules/postcss-loader/dist/index.js
/Users/abc/node_modules/postcss-loader/dist/cjs.js
/Users/abc/node_modules/loader-runner/lib/loadLoader.js
/Users/abc/node_modules/loader-runner/lib/LoaderRunner.js
/Users/abc/node_modules/webpack/lib/NormalModule.js
/Users/abc/node_modules/webpack-manifest-plugin/dist/index.js
/Users/abc/node_modules/react-scripts/config/webpack.config.js
/Users/abc/node_modules/react-scripts/scripts/start.js
(#/Users/abc/node_modules/bootstrap/dist/css/bootstrap.css)
Thank you so much
I've tried updating to the latest version of node and npm, however, that did not help. I've also verified my code several times as I'm mostly practicing along with a course. Thank you.
As it appears this error will temporarily get fixed by installing the latest version of Node.js.
So to fix this follow these steps:
Download and install the latest Node.js version (recommended for most users, which is 16.15.0 at this moment).
Delete your node_modules directory from your project. Then you can optionally clear npm cache with npm cache clean and verify it with npm cache verify.
Delete package-lock.json/yarn.lock file.
Reinstall all of the dependencies and create a new dependency tree using one of the following commands: npm i/npm install/yarn/yarn install.
Note1: If in any case, you use node-sass in React projects yet, it is recommended to use sass instead.
Note2: In some cases skipping step 1 will also work as expected, but I recommend upgrading the Node.js version if you do not have other dependencies to prevent that.
Note3: As #IvaniltonBezerra mentions in the comments, some app builds may throw errors, since upgrading Node.js to its latest version will upgrade the npm as well it may not compatible with your current dependency tree in production, so to prevent such a problem you have to use --legacy-peer-deps to restore the old behaviour of the old dependencies.
Update
This is now seem to be permanently solved in PostCSS Preset Env and following the above steps with skipping step 1 will also solve the problem.
This is done in VS Code. I have seen TONS OF similar posts, so this is a common occurence. I think it maybe stems from a misunderstanding of gradle builds so any help is greatly appreciated! I created a react-native app following their CLI guide. Running the command react-native android did not work, and I followed a stack overflow solution here https://stackoverflow.com/questions/60844245/how-solve-could-not-initialize-class-org-codehaus-groovy-reflection-reflectionc. The command works, and an emulator is created properly, without having to go into android studio and starting it from there. I do a little bit of coding, and then want to install some extensions. I install flow, and babel E6, boom react-native run-android no longer works. A workaround is to start from android studio. I have followed countless stackoverflow answers on the same question as this title, example gradlew.bat install debug error. I gave up and decided to start a new project, boom run-android doesn't work as it seems is standard. I change my gradle version as per the first link, and the command works now for this second project.
Gradlew --version of 1st project:
Gradle 6.3
------------------------------------------------------------
Build time: 2020-03-24 19:52:07 UTC
Revision: bacd40b727b0130eeac8855ae3f9fd9a0b207c60
Kotlin: 1.3.70
Groovy: 2.5.10
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 15.0.1 (Oracle Corporation 15.0.1+9-18)
OS: Windows 10 10.0 amd64
gradlew help of 1st project:
BUILD SUCCESSFUL in 5s
1 actionable task: 1 executed
gradlew build --warning-mode=all of first project:
The BuildListenr.buildStarted(Gradle) method has been deprecated
Internal API constructor DefaultDomainObjectSet(Class<T>) has been deprecated.
Injecting the input artifact of a transform as a File has been dprecated.
So from my understanding on their troubleshooting site, the issue lies with one of the requested tasks rather than a configuration step.
Furthermore I have tried disabling the flow and babel extensions, as well as remove the added config files that weren't included in the react-native init app. I have also tried changing the package.json file to the same as the working second project. Even if a solution is found for this project, I am still curious as to why everytime I start a react-native project I have to change the gradle version in gradle/gradle-wrapper.properties. Any help or input is greatly appreciated.
When I run an Ionic 3 project using the ionic serve command, then I am getting this error:
For a non-Angular general answer for those who land on this question from Google:
Most times when you face this error it’s probably because of a memory leak, an addition/version upgrade of a library or a difference in how Node.js manages memory between versions (e.g. Node.js version <= 10 and Node.js version > 10).
Usually just increasing the memory allocated to Node.js will allow your program to run but may not actually solve the real problem and the memory used by the node process could still exceed the new memory you allocate. I'd advise profiling memory usage in your Node.js process when it starts running or updating to Node.js > 10.
I had a memory leak.
Here is a great article on debugging memory leaks in Node.js.
That said, to increase the memory, in the terminal where you run your Node.js process:
export NODE_OPTIONS="--max-old-space-size=8192"
where values of max-old-space-size can be: [2048, 4096, 8192, 16384] etc
More examples for further clarity:
export NODE_OPTIONS="--max-old-space-size=5120" # Increase to 5 GB
export NODE_OPTIONS="--max-old-space-size=6144" # Increase to 6 GB
export NODE_OPTIONS="--max-old-space-size=7168" # Increase to 7 GB
export NODE_OPTIONS="--max-old-space-size=8192" # Increase to 8 GB
# and so on...
# formula:
export NODE_OPTIONS="--max-old-space-size=(X * 1024)" # Increase to X GB
# Note: it doesn't have to be multiples of 1024.
# max-old-space-size can be any number of memory megabytes (MB) you have available.
See the current value of max-old-space-size (in MB)
To see the current (not exact but very close) value of max-old-space-size (in MB), run in your terminal
node -e 'console.log(v8.getHeapStatistics().heap_size_limit/(1024*1024))'
In my case, I fixed this problem by installing Node.js, version 12.10.0.
I had the same issue on CentOS server 7, but this solved my problem:
node --max-old-space-size=X node_modules/#angular/cli/bin/ng build --prod
Where X = (2048 or 4096 or 8192 o..) is the value of memory.
Just type this in the terminal:
export NODE_OPTIONS="--max-old-space-size=8192"
The error occurs when you exceed the default maximum memory allowed for Node.js. All this does is increase the maximum memory allowed.
I got the same error when I execute ng build command in Visual Studio Code. But I can build successfully when I execute the same thing on the Windows command line in the following sequence.
Step 1.
set NODE_OPTIONS=--max_old_space_size=4096
Step 2.
ng build
Try this solution which was pointed out in an old message on the forum: 3.7.0: iOS build with --prod not working
Open node_modules/#ionic/app-scripts/bin/ionic-app-scripts.js
Change the first line from:
#!/usr/bin/env node
to
#!/usr/bin/env node --max-old-space-size=4096
Try values 1024 and 2048, but for a relatively large app you may need 4096.
Windows
From the control panel go to System → Advanced system settings → Environment Variables → New (user or system)
Or this can be done in PowerShell with:
$env:NODE_OPTIONS="--max-old-space-size=8192"
You can also increase this number, if necessary. We've seen folks need to increase this up to 14 GB for some larger projects!
Linux/macOS
export NODE_OPTIONS=--max-old-space-size=8192
In my case it was a recursion that was causing React to use up all memory.
This happened when I was refactoring my code and didn't notice this.
const SumComponent = () => {
return (
<>
<SumComponent />
</>
)
}
In other Node.js applications this might look like:
const someFunction = () => {
...
someFunction();
...
}
I got the same error message when I executed the following statements in Visual Studio Code. But I can build successfully when I execute the same thing in on the Windows command line.
npm install -g increase-memory-limit
increase-memory-limit
set NODE_OPTIONS=--max_old_space_size=4096
ng build -c deploy --build-optimizer --aot --prod --sourceMap
Updating from Node.js 12 to Node.js 14 solved the problem for me.
Update Now Node.js 16 is available, and I recommend updating to the latest available version of Node.js.
For some reasons all the previous answers didn't really work for me. I did the following to fix my issue:
I had to first delete the node_modules folder
reinstall Node.js on my PC and
then npm install
Adding parameter --build-optimizer resolved the issue in my case:
node --max_old_space_size=4096 ./node_modules/#angular/cli/bin/ng build --prod --build-optimizer
I am not sure why adding only --build-optimizer solves the issue, but as per the Angular documentation it should be used with ahead-of-time (AOT) compilation enabled, so the updated command should be like below:
--build-optimizer=true --aot=true
Angular build documentation
export NODE_OPTIONS="--max-old-space-size=6144" #it will increase to 6gb.
-------If Not Solved try this 2nd step-------------
2) Just update your node version to the latest one will solve this issue.
-------If Not Solved try this 3rd step-------------
3)Just run this command in your windows terminal.
set NODE_OPTIONS=--max_old_space_size=4096
node --max_old_space_size=4096 node_modules/#angular/cli/bin/ng build --baseHref=/baseUrl/ --prod=true
For me, I had a syntax error (which didn't show up) and caused this error.
Run this command in your project folder. Use serve instead of build
node --max_old_space_size=8000 node_modules/#angular/cli/bin/ng serve --prod --port=4202
Replace the line
"start": "ng serve -o --port 4300 --configuration=en" with
"start": "node --max_old_space_size=5096 node_modules/#angular/cli/bin/ng serve -o --port 4300 --configuration=en"
NOTE:
port--4300 is not constant depends upon which port you selects.
--max_old_space_size=5096 too not constant; any value 1024,2048,4096 etc
I faced the same problem on Angular. Then I wrote
"serve": "node --max_old_space_size=8192 ./node_modules/#angular/cli/bin/ng serve"
this script to package.json scripts and for me this problem solved.
And run project this command:
npm run serve
Instead of using ng build, I have executed below command in terminal to fix this issue.
node --max_old_space_size=8192 ./node_modules/#angular/cli/bin/ng build --prod
Then do ng serve.
This is how my terminal look like
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS D:\ProjectPath\Project1> node --max_old_space_size=8192 ./node_modules/#angular/cli/bin/ng build --prod
For me it was a problem with a Firebase package.
Only add "#firebase/database": "0.2.1" for your package.json file. Reinstall node_modules and it works.
For me, the issue was having an extra node_modules folder that I renamed to node_modules_old and running an npm install to generate a fresh node_modules. Somehow the build must have still been picking up the node_modules_old folder, so I moved node_modules_old out of the directory to fix the issue.
I deleted the existing Node.js module and ran the below commands to fix my issue:
npm install -all
npm audit fix
Run this command:
export NODE_OPTIONS="--max-old-space-size=2048"
To check how much you have already:
> node
> v8.getHeapStatistics()
{
total_heap_size: 6049792,
total_heap_size_executable: 524288,
total_physical_size: 5477720,
total_available_size: 1094444024,
used_heap_size: 4141728,
heap_size_limit: 1098907648,
malloced_memory: 8192,
peak_malloced_memory: 582752,
does_zap_garbage: 0,
number_of_native_contexts: 2,
number_of_detached_contexts: 0
}
and then heap_size_limit: 1098907648
Please check your Node.js version:
node -v
If it’s 10.1.1 something, then you need to update your root level Node.js version via the below commands:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
source ~/.nvm/nvm.sh
nvm ls
nvm install 12.18.1
Once done, please restart your terminal or Visual Studio.
It's working 100$.
For Ionic users, please add the below code in your package.json
"ionic:build": "node --max-old-space-size=16384 ./node_modules/#ionic/app-scripts/bin/ionic-app-scripts.js build",
Another non-Angular answer (I was facing the same issue building a React application on AWS Amplify).
As mentioned by Emmanuel, it seems that it comes from the difference in the way memory is handled by Node.js v10 vs. Node.js v12.
I tried to increase memory with no avail. But using Node.js v12 did it.
Check how you can add nvm use $VERSION_NODE_12 to your build settings as explained by richard
frontend:
phases:
preBuild:
commands:
- nvm use $VERSION_NODE_12
- npm ci
build:
commands:
- nvm use $VERSION_NODE_12
- node -v
- npm run-script build
I guess there are plenty of ways to reach this error!
On my side, I had a loop in my package.json. Project A had a dependency on project B, that had a dependency on project A.
Just run this command:
export NODE_OPTIONS="--max-old-space-size=8192"
If you are developing on Windows and running into this issue while publishing, upgrade Node.js through the official site.
The memory usage handling does increase with each newer version of Node.js, although I did not find exact numbers on what the increase is.
That was the only solution that worked for me. It took a whole weekend and more for me to solve this issue.
I am using the latest stable version of Node.js v-14.17. I was having the same issue with new Angular Ionic projects and tried most of the previous answers without success.
Finally after upgrading to Node.js 16.4.2 LTS, it fixed this issue.
For me I got this error because I lost access to the output path for the dist folder set in my angular.json file. After I reconnected to the remote path with updated credentials the error went away.
I ejected from expo, and trying react-native run-android, I'm getting this error;
FAILURE: Build failed with an exception.
* Where:
Script 'C:\Users\simil\OneDrive\Documents\Codes\react-native\expo\doc\node_modules\react-native-unimodules\gradle.groovy' line: 81
* What went wrong:
A problem occurred evaluating project ':app'.
> You need to have MainApplication in your project
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 14s
This is my MainActivity path
MyApp\android\app\src\main\java\com\com.example.eg\MainActivity.java
I faced this problem on my project too, reason was, I ejected from expo, reversed the eject and changed the bundleid. After that I ejected again.
This created 2 different MainApplication.java under app/src/main/java.
To fix it I removed the one with the old bundleid folder.
Also having trouble with this. I’m on Windows 10 and just ejected from expo sdk 37. Its a problem of the react-native-unimodules package.
Seems like findMainJavaApp in line 77 of gradle.groovy doesn’t find the full path of the MainApplication.java (or MainApplication.kt)
rootProject.getProjectDir().getPath() gets only to the android project dir… and not down to the app.src…com.XXX where your MainApplication is.
For a quick fix replace the rootProject.getProjectDir().getPath() in lines 77 and 78 with the absolute path of the parent directory of your projects MainApplication.java (or .kt) file.
I’ll try to post an issue about this in unimodules Github ASAC.
It happened to me the same when I ejected the Expo project from ExpoKit to a BareFlow react-native project.
If you check in your java src path, you will find 2 MainApplication.java, one version is your real MainApplication in your correct package, the other one helps ExpoKit to do its stuff.
During the ejection, for unknown reason, the ExpoKit package com.host.exp should be removed but it is not.
I backed it up, or removed it, and then adjusted some eventual dependencies left in your package like the DEBUG variable.
The problem should go away
I try to use node-vlc with nw.js (v0.12.0-alpha2). When i launch my app without nw.js it works, but when i launch it with nw.js i got an error:
Uncaught Error: Module did not self-register.", source: /home/alexis/Bureau/dev/jukebox/node_modules/vlc/node_modules/ffi/node_modules/bindings/bindings.js (84)
I tried some commands with nw-gyp but it couldn't help me.
I am on Ubuntu 14, 64-bit.
If you've upgraded node then npm rebuild might fix this for you
For me:
rm -r node_modules then
npm install
I had a similar issue with another product and my fix was to change the version of node I was using. I was using 0.12.0 and changed back to 0.10.26.
Personally, I use NVM to handle node version changing. With NVM installed it's as simple as running
nvm use 0.10.26
Or setting the default version to 0.10.26
nvm alias default 0.10.26
Hopefully this helps you out - our issues came from different products but the solution may be the same.
I had similar problem.
/Users/user/NodeAddons/bridge/node_modules/bindings/bindings.js:83
Error: Module did not self-register.
In my case I was doing a C/C++ Add-on, and I had forgotten to export the add-on, in my main.cc was missing the code below:
void Init(v8::Handle<v8::Object> exports) {
NODE_SET_METHOD(exports, "method", method);
}
NODE_MODULE(method, Init);
Hope this helps others!
Thanks :)
I've add the same issue because I installed to modules as sudo...
Removing the node modules folder and reinstalling as normal user fixed it.
For me npm rebuild or npm update didn't work. I had to remove the node_modules folder and run npm install to install them again.
I once had this problem when creating a multi-file c++ addon. In my binding.gyp file I had:
"sources": ["src/*.cc", "src/*.h" ]
And my project contained several *.cc files. However, the NODE_MODULE() macro was called only on one file which imported the rest of the files. But node expects that it is called on the frist *.cc file listed in sources. So I had to change sources to explicitly add that file to the beginning
For me, running npm update worked
I was getting an internal error: Module did not self-register.
Deleted the node_modules folder
ran npm install
It worked just fine.
I had this error with Snappy. Was using Node 11. Checked Snappy's NPM page https://www.npmjs.com/package/snappy where they listed which versions of node they supported.
Deleting node_modules folder rm -rf node_modules and then reinstalling using the correct version of Node resolved it.
One of the versions they supported on Linux at the time of this writing was Node version 12.
nvm deactivate 11
nvm uninstall 11
nvm install 12
nvm use 12
Problem solved
Another cause of this problem: if you're using pm2, then after upgrading node you may need to reinstall pm2. Test whether pm2 is the issue by running your app
without pm2 node server.js
then with pm2: pm2 start server.js.
Proper way to update PM2 after updating Node.js
I had this same issue with 0.12 and io.js 1.3.0, reverting to Node.js 0.10 fixed the issue.
Rebuild your C++ add-ons.
Did you encounter something like this?
Module did not self-register: '…\node_modules\#u4\opencv4nodejs\build\Release\opencv4nodejs.node
It’s likely that you have just updated your Node.js. Once you updated your Node.js, you need to rebuild your C++ add-ons, Node.js packages written in C++.
Why
When you build Node.js’ C++ add-ons, they get compiled into require-able .node files and linked to the currently installed Node.js ABI library, which is not compatible with other versions of it. Your packages were built only compatible with the specific version of Node.js.
How
Firstly, try npm rebuild. If your C++-add-on-based packages have a build script, it’ll do. If it doesn’t, you need to manually build your C++ native add-on packages. Do again what you did when you were installing such packages. Refer to the building instructions in the packages’ documentations to rebuild them. Or try reinstalling (npm install) them.
I had the same problem. My script that was referencing a global reference script had an invalid reference. I took off that invalid reference and the error was gone. My error message had no indication of that particular invalid reference which made it harder to debug. But 'Uncaught Error: Module did not self-register' was the message I was getting.
This also happen in my other project. For some reason, it wouldn't recognize the reference path if one of the characters are uppercase. Even thought, the upper-casing was the correct spelling of the path.
I had this issue while setting up my Cypress project.
I found out the issue was caused because Cypress uses node from its bundle version by default (which was version 8.0 in my case) , whilst the package I wanted to use required the node version to be 10 or higher.
I did have node 12.0 installed on my machine but since cypress was not using that I had to add the line shown below in the settings file (cypress.json) to set the value for 'nodeVersion' to 'system', to tell cypress explicitly to use the node version installed on my machine.
Add this line to your settings file:
**"nodeVersion": "system"**