Skip to main content
edited tags
Link
some-user
  • 4.7k
  • 6
  • 23
  • 54
added 659 characters in body
Source Link
Anonymous Creator
  • 3.6k
  • 8
  • 35
  • 88

I created nest js project as following.

nest new project-name

and imported following from nuxt3 which is of type module of node js with mjs file extension (type definition of import doesn't require to write mjs).

import { ViteBuildContext, ViteOptions, bundle } from '@nuxt/vite-builder-edge';

It gives me below error.

Uncaught Error Error [ERR_REQUIRE_ESM]: require() of ES Module c:\project\node_modules\@nuxt\vite-builder-edge\dist\index.mjs not supported. Instead change the require of c:\project\node_modules\@nuxt\vite-builder-edge\dist\index.mjs to a dynamic import() which is available in all CommonJS modules.

So I tried adding "type": "module" in package.json so now I am getting below error.

Uncaught ReferenceError ReferenceError: exports is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and 'c:\project\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. at <anonymous> (c:\project\dist\main.js:2:23)

How do I fix this? Error is related to typescript (or say compiled javascript) is unable to import mjs exports. What is solution to this?

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false
  }
}

I created nest js project as following.

nest new project-name

and imported following from nuxt3 which is of type module of node js with mjs file extension (type definition of import doesn't require to write mjs).

import { ViteBuildContext, ViteOptions, bundle } from '@nuxt/vite-builder-edge';

It gives me below error.

Uncaught Error Error [ERR_REQUIRE_ESM]: require() of ES Module c:\project\node_modules\@nuxt\vite-builder-edge\dist\index.mjs not supported. Instead change the require of c:\project\node_modules\@nuxt\vite-builder-edge\dist\index.mjs to a dynamic import() which is available in all CommonJS modules.

So I tried adding "type": "module" in package.json so now I am getting below error.

Uncaught ReferenceError ReferenceError: exports is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and 'c:\project\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. at <anonymous> (c:\project\dist\main.js:2:23)

How do I fix this? Error is related to typescript (or say compiled javascript) is unable to import mjs exports. What is solution to this?

I created nest js project as following.

nest new project-name

and imported following from nuxt3 which is of type module of node js with mjs file extension (type definition of import doesn't require to write mjs).

import { ViteBuildContext, ViteOptions, bundle } from '@nuxt/vite-builder-edge';

It gives me below error.

Uncaught Error Error [ERR_REQUIRE_ESM]: require() of ES Module c:\project\node_modules\@nuxt\vite-builder-edge\dist\index.mjs not supported. Instead change the require of c:\project\node_modules\@nuxt\vite-builder-edge\dist\index.mjs to a dynamic import() which is available in all CommonJS modules.

So I tried adding "type": "module" in package.json so now I am getting below error.

Uncaught ReferenceError ReferenceError: exports is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and 'c:\project\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. at <anonymous> (c:\project\dist\main.js:2:23)

How do I fix this? Error is related to typescript (or say compiled javascript) is unable to import mjs exports. What is solution to this?

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false
  }
}
deleted 114 characters in body
Source Link
Anonymous Creator
  • 3.6k
  • 8
  • 35
  • 88

I created nest js project as following.

nest new project-name

and imported following from nuxt3 which is of type module of node js with mjs file extension (type definition of import doesn't require to write mjs).

import { ViteBuildContext, ViteOptions, bundle } from '@nuxt/vite-builder-edge';

It gives me below error.

Uncaught Error Error [ERR_REQUIRE_ESM]: require() of ES Module c:\Users\user\Documents\GitLab\discobite\node_modules\@nuxt\vite\project\node_modules\@nuxt\vite-builder-edge\dist\index.mjs not supported. Instead change the require of c:\Users\user\Documents\GitLab\project\node_modules\@nuxt\vite\project\node_modules\@nuxt\vite-builder-edge\dist\index.mjs to a dynamic import() which is available in all CommonJS modules.

So I tried adding "type": "module" in package.json so now I am getting below error.

Uncaught ReferenceError ReferenceError: exports is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and 'c:\Users\user\Documents\GitLab\project\package\project\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. at <anonymous> (c:\Users\user\Documents\GitLab\project\dist\main\project\dist\main.js:2:23)

How do I fix this? Error is related to typescript (or say compiled javascript) is unable to import mjs exports. What is solution to this?

I created nest js project as following.

nest new project-name

and imported following from nuxt3 which is of type module of node js with mjs file extension (type definition of import doesn't require to write mjs).

import { ViteBuildContext, ViteOptions, bundle } from '@nuxt/vite-builder-edge';

It gives me below error.

Uncaught Error Error [ERR_REQUIRE_ESM]: require() of ES Module c:\Users\user\Documents\GitLab\discobite\node_modules\@nuxt\vite-builder-edge\dist\index.mjs not supported. Instead change the require of c:\Users\user\Documents\GitLab\project\node_modules\@nuxt\vite-builder-edge\dist\index.mjs to a dynamic import() which is available in all CommonJS modules.

So I tried adding "type": "module" in package.json so now I am getting below error.

Uncaught ReferenceError ReferenceError: exports is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and 'c:\Users\user\Documents\GitLab\project\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. at <anonymous> (c:\Users\user\Documents\GitLab\project\dist\main.js:2:23)

How do I fix this? Error is related to typescript (or say compiled javascript) is unable to import mjs exports. What is solution to this?

I created nest js project as following.

nest new project-name

and imported following from nuxt3 which is of type module of node js with mjs file extension (type definition of import doesn't require to write mjs).

import { ViteBuildContext, ViteOptions, bundle } from '@nuxt/vite-builder-edge';

It gives me below error.

Uncaught Error Error [ERR_REQUIRE_ESM]: require() of ES Module c:\project\node_modules\@nuxt\vite-builder-edge\dist\index.mjs not supported. Instead change the require of c:\project\node_modules\@nuxt\vite-builder-edge\dist\index.mjs to a dynamic import() which is available in all CommonJS modules.

So I tried adding "type": "module" in package.json so now I am getting below error.

Uncaught ReferenceError ReferenceError: exports is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and 'c:\project\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. at <anonymous> (c:\project\dist\main.js:2:23)

How do I fix this? Error is related to typescript (or say compiled javascript) is unable to import mjs exports. What is solution to this?

Source Link
Anonymous Creator
  • 3.6k
  • 8
  • 35
  • 88
Loading