Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while importing a NPM package #2320

Closed
onderbakirtas opened this issue Aug 29, 2021 · 3 comments
Closed

Error while importing a NPM package #2320

onderbakirtas opened this issue Aug 29, 2021 · 3 comments

Comments

@onderbakirtas
Copy link

onderbakirtas commented Aug 29, 2021

Describe the bug

Importing a module gives error, even though not using it.

Reproduction

Here is the repo link: https://github.com/onderbakirtas/bug-report

Logs

6:22:19 PM [vite] Error when evaluating SSR module C:\Users\onder\Desktop\node_apps\blog1\src\routes\index.json.js:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\onder\Desktop\node_apps\blog1\node_modules\to-vfile\index.js
require() of ES modules is not supported.
require() of C:\Users\onder\Desktop\node_apps\blog1\node_modules\to-vfile\index.js from C:\Users\onder\Desktop\node_apps\blog1\node_modules\vite\dist\node\chunks\dep-972722fa.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\onder\Desktop\node_apps\blog1\node_modules\to-vfile\package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at nodeRequire (C:\Users\onder\Desktop\node_apps\blog1\node_modules\vite\dist\node\chunks\dep-972722fa.js:73811:17)
    at ssrImport (C:\Users\onder\Desktop\node_apps\blog1\node_modules\vite\dist\node\chunks\dep-972722fa.js:73753:20)
    at eval (C:\Users\onder\Desktop\node_apps\blog1\src\routes\index.json.js:6:37)
    at async instantiateModule (C:\Users\onder\Desktop\node_apps\blog1\node_modules\vite\dist\node\chunks\dep-972722fa.js:73796:9)
Must use import to load ES Module: C:\Users\onder\Desktop\node_apps\blog1\node_modules\to-vfile\index.js
require() of ES modules is not supported.
require() of C:\Users\onder\Desktop\node_apps\blog1\node_modules\to-vfile\index.js from C:\Users\onder\Desktop\node_apps\blog1\node_modules\vite\dist\node\chunks\dep-972722fa.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\onder\Desktop\node_apps\blog1\node_modules\to-vfile\package.json.
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)                                     s\blog1\node_modules\to-vfile\index.js
    at nodeRequire (C:\Users\onder\Desktop\node_apps\blog1\node_modules\vite\dist\node\chunks\dep-972722fa.js:73811:17)                                                               Users\onder\Desktop\node_apps\blog1\node_modules\vite\dist\node\chunks\dep-972722fa.js is an ES module file as
    at ssrImport (C:\Users\onder\Desktop\node_apps\blog1\node_modules\vite\dist\node\chunks all .js files in that package scope as ES modules.\dep-972722fa.js:73753:20)                                                                 e "type": "module" from C:\Users\onder\Desktop\node_apps\blog1\node_modules\to-vfile\package.json.
    at eval (C:\Users\onder\Desktop\node_apps\blog1\src\routes\index.json.js:6:37)
    at async instantiateModule (C:\Users\onder\Desktop\node_apps\blog1\node_modules\vite\dist\node\chunks\dep-972722fa.js:73796:9)
Unexpected token E in JSON at position 0
SyntaxError: Unexpected token E in JSON at position 0
    at JSON.parse (<anonymous>)
    at Proxy.<anonymous> (file:///C:/Users/onder/Desktop/node_apps/blog1/node_modules/@svelks\dep-972722fa.js:73811:17)tejs/kit/dist/ssr.js:923:22)                                                               \dep-972722fa.js:73753:20)
    at async load (index.svelte:4:24)
    at async load_node (file:///C:/Users/onder/Desktop/node_apps/blog1/node_modules/@sveltest\node\chunks\dep-972722fa.js:73796:9)js/kit/dist/ssr.js:951:12)
    at async respond$1 (file:///C:/Users/onder/Desktop/node_apps/blog1/node_modules/@sveltejs/kit/dist/ssr.js:1235:15)
    at async render_page (file:///C:/Users/onder/Desktop/node_apps/blog1/node_modules/@sveltejs/kit/dist/ssr.js:923:22)tejs/kit/dist/ssr.js:1399:19)
    at async resolve (file:///C:/Users/onder/Desktop/node_apps/blog1/node_modules/@sveltejsjs/kit/dist/ssr.js:951:12)/kit/dist/ssr.js:1662:10)                                                                  js/kit/dist/ssr.js:1235:15)
    at async respond (file:///C:/Users/onder/Desktop/node_apps/blog1/node_modules/@sveltejstejs/kit/dist/ssr.js:1399:19)/kit/dist/ssr.js:1641:10)                                                                  /kit/dist/ssr.js:1662:10)
    at async Immediate.<anonymous> (file:///C:/Users/onder/Desktop/node_apps/blog1/node_mod/kit/dist/ssr.js:1641:10)ules/@sveltejs/kit/dist/chunks/index.js:3511:22)

System Info

System:
    OS: Windows 10 10.0.19043
    CPU: (12) x64 AMD Ryzen 5 1600 Six-Core Processor
    Memory: 8.37 GB / 15.94 GB
  Binaries:
    Node: 14.15.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.14.8 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1023.0), Chromium (92.0.902.84)
    Internet Explorer: 11.0.19041.906
  npmPackages:
    @sveltejs/adapter-static: ^1.0.0-next.17 => 1.0.0-next.17
    @sveltejs/kit: next => 1.0.0-next.159
    svelte: ^3.34.0 => 3.42.4

Severity

blocking all usage of SvelteKit

Additional Information

Using it like this:

import vile from 'to-vfile';
@benmccann
Copy link
Member

it's an esm module: https://github.com/vfile/to-vfile/blob/d53c24488ca6ad1e155a04b8d918c18ebbfc3aef/package.json#L29

unfortunately vite can't handle for ssr yet, but hopefully will be fixed soon

closing as duplicate of vitejs/vite#4450

@korywka
Copy link

korywka commented Dec 3, 2021

@benmccann please consider to update vite: vitejs/vite#5197

@benmccann
Copy link
Member

Vite 2.7 will be released on Monday and we will update when that occurs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants