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 on import? #151

Open
arcfide opened this issue Jun 18, 2020 · 7 comments
Open

Error on import? #151

arcfide opened this issue Jun 18, 2020 · 7 comments

Comments

@arcfide
Copy link

arcfide commented Jun 18, 2020

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'
```
@arlac77
Copy link
Owner

arlac77 commented Jun 28, 2020

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

@arcfide
Copy link
Author

arcfide commented Jun 28, 2020

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.

@arcfide
Copy link
Author

arcfide commented Jun 28, 2020

My specific node version is 12.17.0

@arlac77
Copy link
Owner

arlac77 commented Jun 29, 2020

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

@ashwinvasudevan
Copy link

Same here.

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

@arlac77
Copy link
Owner

arlac77 commented Jan 7, 2021

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.

@lucaspontoexe
Copy link
Contributor

You can try to import the full path:

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

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

4 participants