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.

ES Modules not supported with NextJS

See original GitHub issue

HI, I am receiving the following bug: image

My project dependencies are:

package.json

{
  "name": "pfc_next_frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "debug": "NODE_OPTIONS='--inspect' next dev",
    "dev-logger": "NODE_OPTIONS='-r next-logger' next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@apollo/client": "^3.6.9",
    "@hookform/resolvers": "^2.9.5",
    "@stripe/react-stripe-js": "^1.9.0",
    "@stripe/stripe-js": "^1.32.0",
    "@tailwindcss/forms": "^0.5.2",
    "@tinymce/tinymce-react": "^4.1.0",
    "antd": "^4.21.6",
    "autoprefixer": "^10.4.7",
    "axios": "^0.27.2",
    "cookie": "^0.5.0",
    "cpf-cnpj-validator": "^1.0.3",
    "daisyui": "^2.19.0",
    "date-fns": "^2.28.0",
    "date-fns-tz": "^1.3.5",
    "dotenv": "^16.0.1",
    "graphql": "^16.5.0",
    "i18next": "^21.8.13",
    "ioredis": "^5.2.0",
    "joi": "^17.6.0",
    "less": "^4.1.3",
    "less-loader": "^11.0.0",
    "localtunnel": "^2.0.2",
    "micro": "^9.3.4",
    "micro-cors": "^0.1.1",
    "next": "12.2.0",
    "next-logger": "^3.0.1",
    "next-seo": "^5.4.0",
    "next-with-less": "^2.0.5",
    "postcss": "^8.4.14",
    "postcss-import": "^14.1.0",
    "postcss-preset-env": "^7.7.2",
    "react": "^18.2.0",
    "react-cookie": "^4.1.1",
    "react-daisyui": "^2.0.6",
    "react-dom": "^18.2.0",
    "react-dropzone": "^14.2.2",
    "react-hook-form": "^7.33.1",
    "react-i18next": "^11.18.0",
    "react-icons": "^4.4.0",
    "react-number-format": "^4.9.3",
    "react-paginate": "^8.1.3",
    "react-password-strength-bar": "^0.4.1",
    "react-phone-input-2": "^2.15.1",
    "react-range": "^1.8.13",
    "react-select": "^5.4.0",
    "react-table": "^7.8.0",
    "react-toastify": "^9.0.5",
    "sharp": "^0.30.7",
    "showdown": "^2.1.0",
    "slugify": "^1.6.5",
    "socket.io": "^4.5.1",
    "socket.io-client": "^4.5.1",
    "stripe": "^9.12.0",
    "styled-components": "^5.3.5",
    "swiper": "^8.3.0",
    "tailwind.macro": "^0.5.10",
    "tailwindcss": "^3.1.6",
    "web-vitals": "^2.1.4",
    "yup": "^0.32.11"
  },
  "devDependencies": {
    "@hookform/devtools": "^4.2.0",
    "@tailwindcss/aspect-ratio": "^0.4.0",
    "@tailwindcss/line-clamp": "^0.4.0",
    "@tailwindcss/typography": "^0.5.3",
    "@types/gtag.js": "^0.0.10",
    "@types/i18next": "^13.0.0",
    "@types/micro": "^7.3.7",
    "@types/node": "^18.0.3",
    "@types/react": "^18.0.15",
    "@types/react-dom": "^18.0.6",
    "@types/react-i18next": "^8.1.0",
    "@types/react-paginate": "^7.1.1",
    "@types/react-table": "^7.7.12",
    "@types/showdown": "^2.0.0",
    "@types/styled-components": "^5.1.25",
    "eslint": "^8.19.0",
    "eslint-config-next": "12.2.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-react-hooks": "^4.6.0",
    "prettier": "^2.7.1",
    "tslib": "^2.4.0",
    "typescript": "^4.7.4"
  }
}

tsconfig.json

{
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig.json to read more about this file */
    /* Basic Options */
    // "incremental": true /* Enable incremental compilation */,
    "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
    "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ] /* Specify library files to be included in the compilation. */,
    "allowJs": true /* Allow javascript files to be compiled. */,
    "checkJs": false /* Report errors in .js files. */,
    "jsx": "preserve" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
    "declaration": true /* Generates corresponding '.d.ts' file. */,
    "declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */,
    // "outFile": "./",                       /* Concatenate and emit output to single file. */
    // "outDir": "./build" /* Redirect output structure to the directory. */,
    // "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
    // "composite": true /* Enable project compilation */,
    // "tsBuildInfoFile": "./",               /* Specify file to store incremental compilation information */
    "removeComments": true /* Do not emit comments to output. */,
    // "noEmit": true /* Do not emit outputs. */,
    "importHelpers": true /* Import emit helpers from 'tslib'. */,
    "downlevelIteration": true /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */,
    "isolatedModules": true /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */,
    /* Strict Type-Checking Options */
    "strict": true /* Enable all strict type-checking options. */,
    "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
    "strictNullChecks": true /* Enable strict null checks. */,
    "strictFunctionTypes": true /* Enable strict checking of function types. */,
    "strictBindCallApply": true /* Enable strict 'bind', 'call', and 'apply' methods on functions. */,
    "strictPropertyInitialization": false /* Enable strict checking of property initialization in classes. */,
    "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
    "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
    /* Additional Checks */
    "noUnusedLocals": true /* Report errors on unused locals. */,
    "noUnusedParameters": true /* Report errors on unused parameters. */,
    "noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
    "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
    "noUncheckedIndexedAccess": true /* Include 'undefined' in index signature results */,
    /* Module Resolution Options */
    "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
    "baseUrl": "./src/" /* Base directory to resolve non-absolute module names. */,
    "paths": {
      "@/*": ["./*"]
    } /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */,
    // "rootDirs": ["./src"] /* List of root folders whose combined content represents the structure of the project at runtime. */,
    // "typeRoots": [] /* List of folders to include type definitions from. */,
    "types": [
      "tslib",
      "gtag.js"
    ] /* Type declaration files to be included in compilation. */,
    "allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
    "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
    "preserveSymlinks": false /* Do not resolve the real path of symlinks. */,
    // "allowUmdGlobalAccess": true,          /* Allow accessing UMD globals from modules. */
    /* Source Map Options */
    // "sourceRoot": "",                      /* Specify the location where debugger should locate TypeScript files instead of source locations. */
    // "mapRoot": "",                         /* Specify the location where debugger should locate map files instead of generated locations. */
    // "inlineSourceMap": true /* Emit a single file with source maps instead of having a separate file. */,
    // "inlineSources": true /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */,
    /* Experimental Options */
    "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
    "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,
    "resolveJsonModule": true,
    /* Advanced Options */
    "skipLibCheck": true /* Skip type checking of declaration files. */,
    "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
    "noEmit": true,
    "incremental": true
  },
  "include": [
    "next-env.d.ts",
    "**/*.d.ts",
    "**/*.ts",
    "**/*.tsx",
    "**/*.js",
    "src/hooks"
  ],
  "exclude": ["node_modules"]
}

This issue is quite new for me… Not sure what could be…

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
yudielcurbelocommented, Jul 12, 2022

I’m getting the same error when upgrading from 4.1.0 to 4.2.0

1reaction
jsun969commented, Jul 12, 2022

I see. I’ll use uuid to replace it tommorrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Import ES module in Next.js ERR_REQUIRE_ESM
From Next.js 12, support for ES Modules is now enabled by default, as long as the ESM library has "type": "module" in its...
Read more >
How to Bypass ES Modules Errors in Next.js with Dynamic ...
The snippet above shows how you can import a module with dynamic imports and pass the ssr object as an argument to it....
Read more >
Error: Must use import to load ES Module · Issue #25454
I suspect the initial error that we both faced has something to do with NextJS not supporting ES modules, and I was wondering...
Read more >
Blog - Next.js 11.1
We're working on extensive ES Modules support in Next.js, both as input modules and as an output target. Starting with Next.js 11.1, you...
Read more >
How to enable ES Modules in Node.js - Flavio Copes
js file (or whatever) to app.mjs . Note that now the require() syntax will stop working. For older Node.js versions that might not...
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