ReferenceError: module is not defined in ES module scope
Answered
West African Crocodile posted this in #help-forum
West African CrocodileOP
I have been developing my project happily on my mac, as soon as I move it to my linux VPS, I start getting this stupid error. I am using typescript for my whole project, no js files are in it. Please help, i'm about to rip my hair our as the last time this happened I ended up restarting the project to get rid of the error.
▲ Next.js 14.2.14
- Local: http://localhost:4000
- Environments: .env.local
✓ Starting...
✓ Ready in 1213ms
○ Compiling /middleware ...
✓ Compiled /middleware in 1104ms (449 modules)
○ Compiling / ...
⨯ ./app/globals.css.webpack[javascript/auto]!=!./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[2]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[3]!./app/globals.css
ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/root/DevEnv/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
Import trace for requested module:
./app/globals.css.webpack[javascript/auto]!=!./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[2]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[3]!./app/globals.css
./app/globals.css
GET / 500 in 6095ms
⨯ ./app/globals.css.webpack[javascript/auto]!=!./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[2]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[3]!./app/globals.css
ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/root/DevEnv/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
Import trace for requested module:
./app/globals.css.webpack[javascript/auto]!=!./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[2]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[3]!./app/globals.css
./app/globals.css
GET /next/static/webpack/f1f8feb97646a233.webpack.hot-update.json 500 in 6364ms
GET / 500 in 221ms
⚠ Fast Refresh had to perform a full reload due to a runtime error.
GET / 500 in 6ms
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: ENOENT: no such file or directory, rename '/root/DevEnv/.next/cache/webpack/client-development-fallback/0.pack.gz' -> '/root/DevEnv/.next/cache/webpack/client-development-fallback/0.pack.gz'
✓ Compiled /favicon.ico in 104ms (338 modules)
GET /favicon.ico 500 in 110ms
▲ Next.js 14.2.14
- Local: http://localhost:4000
- Environments: .env.local
✓ Starting...
✓ Ready in 1213ms
○ Compiling /middleware ...
✓ Compiled /middleware in 1104ms (449 modules)
○ Compiling / ...
⨯ ./app/globals.css.webpack[javascript/auto]!=!./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[2]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[3]!./app/globals.css
ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/root/DevEnv/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
Import trace for requested module:
./app/globals.css.webpack[javascript/auto]!=!./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[2]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[3]!./app/globals.css
./app/globals.css
GET / 500 in 6095ms
⨯ ./app/globals.css.webpack[javascript/auto]!=!./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[2]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[3]!./app/globals.css
ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/root/DevEnv/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
Import trace for requested module:
./app/globals.css.webpack[javascript/auto]!=!./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[2]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[14].oneOf[12].use[3]!./app/globals.css
./app/globals.css
GET /next/static/webpack/f1f8feb97646a233.webpack.hot-update.json 500 in 6364ms
GET / 500 in 221ms
⚠ Fast Refresh had to perform a full reload due to a runtime error.
GET / 500 in 6ms
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: ENOENT: no such file or directory, rename '/root/DevEnv/.next/cache/webpack/client-development-fallback/0.pack.gz' -> '/root/DevEnv/.next/cache/webpack/client-development-fallback/0.pack.gz'
✓ Compiled /favicon.ico in 104ms (338 modules)
GET /favicon.ico 500 in 110ms
Answered by West African Crocodile
Their configs are tailwind.config.js and postcss.config.js, simple rename to .cjs fixed it.
11 Replies
@gin what u could do is -> delete .next/ folder and try again
West African CrocodileOP
Done that many times
@gin are you starting your app in dev mode?
West African CrocodileOP
yes
@West African Crocodile Done that many times
try deleting package-lock and node_modules
and running npm i
West African CrocodileOP
It was tailwindcss and postcss
West African CrocodileOP
Their configs are tailwind.config.js and postcss.config.js, simple rename to .cjs fixed it.
Answer
nice!
West African CrocodileOP
Thanks for the suggestions!