3

I just created a new react app with "npx create react app" and when i run it with "npm start" (i haven´t change anything) i got this error:

Compiled with problems:X

ERROR in ./src/App.css (./node_modules/css-loader/dist/cjs.js??ruleSet1.rules1.oneOf[5].use1!./node_modules/postcss-loader/dist/cjs.js??ruleSet1.rules1.oneOf[5].use[2]!./node_modules/source-map-loader/dist/cjs.js!./src/App.css)

Module Error (from ./node_modules/postcss-loader/dist/cjs.js): Loading PostCSS "postcss-preset-env" plugin failed: Cannot find module 'node:vm' Require stack:

  • C:\Users\Nico\Documents\programacion\MernEcomm\frontend\node_modules@csstools\postcss-trigonometric-functions\dist\index.cjs
  • C:\Users\Nico\Documents\programacion\MernEcomm\frontend\node_modules\postcss-preset-env\dist\index.cjs
  • C:\Users\Nico\Documents\programacion\MernEcomm\frontend\node_modules\postcss-loader\dist\utils.js
  • C:\Users\Nico\Documents\programacion\MernEcomm\frontend\node_modules\postcss-loader\dist\index.js
  • C:\Users\Nico\Documents\programacion\MernEcomm\frontend\node_modules\postcss-loader\dist\cjs.js
  • C:\Users\Nico\Documents\programacion\MernEcomm\frontend\node_modules\loader-runner\lib\loadLoader.js
  • C:\Users\Nico\Documents\programacion\MernEcomm\frontend\node_modules\loader-runner\lib\LoaderRunner.js
  • C:\Users\Nico\Documents\programacion\MernEcomm\frontend\node_modules\webpack\lib\NormalModule.js
  • C:\Users\Nico\Documents\programacion\MernEcomm\frontend\node_modules\webpack-manifest-plugin\dist\index.js
  • C:\Users\Nico\Documents\programacion\MernEcomm\frontend\node_modules\react-scripts\config\webpack.config.js
  • C:\Users\Nico\Documents\programacion\MernEcomm\frontend\node_modules\react-scripts\scripts\start.js enter image description here
  • 1
    Duplicate of https://stackoverflow.com/questions/72452453/cra-project-node-v14-17-0-loading-postcss-postcss-preset-env-plugin-failed/72452706#72452706 – SMAKSS May 31 '22 at 18:51
  • Very convenient that this was asked 2 hours ago. We (myself and colleagues) have just come up against this exact same error today! Oddly, my build was working fine until I cleared out my node_modules folder and did a clean npm install. I'll be keeping an eye on this question and will feedback if we find a fix. We are using an older version of node which is probably contributing to the problem. – Steven Bruce May 31 '22 at 18:52
  • Does this answer your question? [CRA project node v14.17.0 - Loading PostCSS "postcss-preset-env" plugin failed: Cannot find module 'node:vm'](https://stackoverflow.com/questions/72452453/cra-project-node-v14-17-0-loading-postcss-postcss-preset-env-plugin-failed) – SMAKSS May 31 '22 at 20:00
  • I just pulled today and got this. – Paul Totzke May 31 '22 at 23:15
  • This was fixed in postcss-preset-env. For support you can always open an issue : https://github.com/csstools/postcss-plugins/issues – R Menke Jun 04 '22 at 16:22

2 Answers2

1

Just ran into this exact thing today and fixed it by installing the latest version of node(16.15.0) -> https://nodejs.org/en/

0

You're most likely trying to use create-react-app on an image, and the image's configurations are crossing wires with create-react-app; that's what I just did by mistake using Docker, and I got the same exact compiling error with node:vm as a missing module

If you're using create-react-app, don't use it while you're in any Docker/Dev Environment images, just run the npx command in your terminal as is (probably helps having node downloaded on your local machine as well)

npx create-react-app my-app --template typescript

Hopefully that helps, I know that solved my problem

Nelson
  • 1
  • 1