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

ReferenceError: require is not defined in ES module scope, you can use import instead #18

Closed
SwiftWinds opened this issue Apr 23, 2022 · 5 comments · Fixed by #22
Closed
Assignees
Labels
bug Something isn't working

Comments

@SwiftWinds
Copy link

When using this package with SvelteKit, I get:

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/Users/matt/Development/ucsb-fake-badge/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at eval (eval at 607 (file:///Users/matt/Development/ucsb-fake-badge/.svelte-kit/output/server/entries/pages/index.svelte.js:66:85), <anonymous>:1:1)
    at Object.607 (file:///Users/matt/Development/ucsb-fake-badge/.svelte-kit/output/server/entries/pages/index.svelte.js:66:85)
    at __webpack_require__ (file:///Users/matt/Development/ucsb-fake-badge/.svelte-kit/output/server/entries/pages/index.svelte.js:448:37)
    at file:///Users/matt/Development/ucsb-fake-badge/.svelte-kit/output/server/entries/pages/index.svelte.js:450:12
    at file:///Users/matt/Development/ucsb-fake-badge/.svelte-kit/output/server/entries/pages/index.svelte.js:451:5
    at file:///Users/matt/Development/ucsb-fake-badge/.svelte-kit/output/server/entries/pages/index.svelte.js:452:3
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:409:24)
    at async Promise.all (index 1)
> 500 /
    at file:///Users/matt/Development/ucsb-fake-badge/node_modules/.pnpm/@[email protected][email protected]/node_modules/@sveltejs/kit/dist/chunks/index2.js:989:11
    at save (file:///Users/matt/Development/ucsb-fake-badge/node_modules/.pnpm/@[email protected][email protected]/node_modules/@sveltejs/kit/dist/chunks/index2.js:1209:4)
    at visit (file:///Users/matt/Development/ucsb-fake-badge/node_modules/.pnpm/@[email protected][email protected]/node_modules/@sveltejs/kit/dist/chunks/index2.js:1100:3)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
 ELIFECYCLE  Command failed with exit code 1.

And it goes away when I remove svelte-persistent-store from my project. Any ideas how to fix this?

@MacFJA MacFJA added the bug Something isn't working label Apr 23, 2022
@MacFJA
Copy link
Owner

MacFJA commented Apr 23, 2022

From my investigation (see here) I seem that the issue came from the dependency esserializer.

I did some tests, and sadly it appear that I won't be able to fix/do a workaround on my side.

@MacFJA MacFJA self-assigned this Apr 23, 2022
@martinkovacik
Copy link

To fix the error change this line

import ESSerializer from "esserializer"

to this: import * as ESSerializer from "esserializer"

@extremegf
Copy link

I solved this problem by downgrading to 1.2.0.

@gyurielf
Copy link

Same here.

@lorenzodonadio
Copy link

downgrading to 1.2.0 also worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants