Skip to content

Error while importing a NPM package #2320

@onderbakirtas

Description

@onderbakirtas

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';

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions