Create React App Error - Loading PostCSS "postcss-preset-env" plugin failed: Cannot find module 'node:vm'

Viewed 1640

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
2 Answers

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

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

Related