arlac77/svelte-websocket-store

Error on import?

Opened this issue · 7 comments

I get the following error when trying to import this module.

internal/modules/cjs/loader.js:984
    throw new ERR_REQUIRE_ESM(filename);
    ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\...\node_modules\svelte-websocket-store\src\index.mjs
    at Module.load (internal/modules/cjs/loader.js:984:11)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (C:\Users\...\__sapper__\dev\server\server.js:10:38)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
  code: 'ERR_REQUIRE_ESM'
}

I'm not sure what's going on here? I'm using this line in my Sapper route code:

import websocketStore from 'svelte-websocket-store'
```

Are You trying this without bundling (rollup, webpack,...) ?
Which version of node You are using ?

To import the module natively with node, a recent 12.x or any 14.x node version is required

I'm trying to import this into a Svelte/Sapper application derived from the rollup template that Sapper provides.

I'm calling yarn run dev to run the application for development. I'm using node 12.x.

By copying the actual index.mjs file into my repository and then renaming it to use a .js extension instead of a .mjs extension, the problem goes away and I can use the code, but I had hoped to be able to use it directly after doing a yarn add.

My specific node version is 12.17.0

I can reproduce the problem with sapper. Looks like sapper has problems with nodes flavor of esm modules

Same here.

I can reproduce the problem with sapper. Looks like sapper has problems with nodes flavor of esm modules

The problem is that svelte-websocket-store only works for with ESM not CJS type of modules.
If you force sapper to product ESM modules on the server site, it should work.

You can try to import the full path:

import websocketStore from "svelte-websocket-store/src/index.mjs";