question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

require is not defined in ES module scope, you can use import instead

See original GitHub issue

Environment

  • Operating System: Darwin
  • Node Version: v14.20.0
  • Nuxt Version: 3.0.0-rc.8
  • Package Manager: npm@6.14.17
  • Builder: vite
  • User Config: css, runtimeConfig, app, build, buildModules, alias, modules
  • Runtime Modules: -
  • Build Modules: @pinia/nuxt@0.4.1

Reproduction

// package.json { “private”: true, “scripts”: { “build”: “nuxt build”, “dev”: “nuxt dev”, “generate”: “nuxt generate”, “generate:dev”: “nuxt generate”, “preview”: “nuxt preview”, “lint”: “eslint --ext .js,.vue,.ts --ignore-path .gitignore .”, “lintfix”: “eslint --fix --ext .js,.vue,.ts --ignore-path .gitignore .”, “precommit”: “npm run lint” }, “devDependencies”: { “@nuxtjs/eslint-config-typescript”: “^10.0.0”, “@nuxtjs/proxy”: “^2.1.0”, “@typescript-eslint/eslint-plugin”: “^5.35.1”, “@typescript-eslint/parser”: “^5.35.1”, “ali-oss”: “^6.17.1”, “co”: “^4.6.0”, “eslint”: “^8.23.0”, “eslint-plugin-vue”: “^9.4.0”, “gulp”: “^4.0.2”, “less-loader”: “^11.0.0”, “nuxt”: “3.0.0-rc.8”, “path”: “^0.12.7”, “through2”: “^4.0.2”, “typescript”: “^4.8.2”, “vue-tsc”: “^0.40.1” }, “dependencies”: { “@nuxt/webpack-builder”: “^3.0.0-rc.8”, “@pinia/nuxt”: “^0.4.1”, “less”: “^4.1.3”, “normalize.css”: “^8.0.1”, “pinia”: “^2.0.21”, “vue-lazyload”: “^3.0.0-rc.2”, “vuex”: “^4.0.2” } }

// nuxt.config.ts import { defineNuxtConfig } from ‘nuxt’

const isProduction = process.env.NODE_ENV === ‘production’ const cdnUrl = ‘xxxxxxx’

let config = defineNuxtConfig({ css: [ ‘assets/styles/base.less’, ‘assets/styles/main.less’ ], runtimeConfig: { public: { cdnUrl: isProduction ? cdnUrl : ‘/’ } }, app: { head: { script: [ { src: ‘/script/changeRootFontSize.js’, async: true } ], meta: [ { charset: ‘utf-8’ }, { name: ‘viewport’, content: ‘width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0,viewport-fit=cover’ }, { name: ‘apple-mobile-web-app-capable’, content: ‘yes’ }, { name: ‘full-screen’, content: ‘true’ }, { name: ‘x5-fullscreen’, content: ‘true’ }, { name: ‘360-fullscreen’, content: ‘true’ } ] } }, build: { transpile: [] }, buildModules: [‘@pinia/nuxt’], alias: { ‘@vue/devtools-api’: ‘@vue/devtools-api’ }, modules: [] })

// error image

image

export default config

Describe the bug

It was no problem to run on the window yesterday, but today I changed the mac and reported this error directly

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
danielroecommented, Sep 8, 2022

Having said that, from the screenshot, it looks like you have run Nuxt 2 at some point in this project. Would you remove your .nuxt folder and retry?

0reactions
danielroecommented, Sep 8, 2022

No problem - glad to find the issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

require is not defined in ES module scope, you can use import ...
Requiring external module babel-register ReferenceError: require is not defined in ES module scope, you can use import instead This file is ...
Read more >
How to fix the error `require is not defined` in Node.js
Solution · change the type of modules in package.json to commonjs : "type": "commonjs" · delete the string "type": "module" from the file...
Read more >
How To Fix ReferenceError require is not defined in JavaScript
In this case, check your package.json file for an property called type . If that is set to module , ES6 modules will...
Read more >
ReferenceError: require is not defined in JavaScript | bobbyhadz
To solve the "ReferenceError require is not defined" error, use the ES6 module import and export syntax. The require() function is Node.js specific...
Read more >
require is not defined in ES module scope, you can use import ...
Trying to follow a DynamoDB + Lambda + API Gateway tutorial: http-api-dynamo-db. ... How to resolve it? and what is causing this issue?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found