square / svelte-store

528 stars 35 forks source link

exports is not defined in ES module scope #7

Closed kuechlerm closed 2 years ago

kuechlerm commented 2 years ago

When using the current version 0.1.3, I have the following error. Rolling back to 0.1.1 fixes the problem.

Error message:

exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and 'C:\Dev\[...]\node_modules\.pnpm\@square+svelte-store@0.1.3\node_modules\@square\svelte-store\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
Akolyte01 commented 2 years ago

Can you create a reproduction in a codesandbox or equivalent? I'll need more information on what kind of environment this occurs to address. Thanks!

kuechlerm commented 2 years ago

You could clone this : https://github.com/kuechlerm/svelte-stores-bug Its a minimal Sveltekit setup. My system versions are in README.md.

kuechlerm commented 2 years ago

I get

exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and 'C:\Dev\svelte-stores-bug\node_modules\@square\svelte-store\package.json' contains "type": "module". 
To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and 'C:\Dev\svelte-stores-bug\node_modules\@square\svelte-store\package.json' contains "type": "module". 
To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///C:/Dev/svelte-stores-bug/node_modules/@square/svelte-store/lib/index.js:60:1
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
    at async nodeImport (C:\Dev\svelte-stores-bug\node_modules\vite\dist\node\chunks\dep-59dc6e00.js:59403:21)
    at async eval (/src/routes/index.svelte:7:31)
    at async instantiateModule (C:\Dev\svelte-stores-bug\node_modules\vite\dist\node\chunks\dep-59dc6e00.js:59333:9)
Akolyte01 commented 2 years ago

the above PR fixes the issue in the project @kuechlerm linked and is confirmed to work in square's projects.

@SarcevicAntonio could you confirm that this PR won't break your project? Thanks

SarcevicAntonio commented 2 years ago

@SarcevicAntonio could you confirm that this PR won't break your project? Thanks

Going to bed now, but I can try to check it out tomorrow when I get a chance 😅

Akolyte01 commented 2 years ago

Ha no hurry at all! Enjoy your night

SarcevicAntonio commented 2 years ago

Sadly I get some errors when my SvelteKit app boots up:

index.ts:327 Uncaught (in promise) ReferenceError: exports is not defined
    at node_modules/@square/svelte-store/lib/index.js (index.ts:327:14)
    at __init (chunk-M5PF3ZFT.js?v=e2583755:25:56)
    at dep:@square_svelte-store:1:16

The dep:@square_svelte-store:1:16 file seems to be generated by Vite and contains export default require("./node_modules/@square/svelte-store/lib/index.js");.

I can't seem to figure out why this happens.

Akolyte01 commented 2 years ago

Sadly I get some errors when my SvelteKit app boots up:

index.ts:327 Uncaught (in promise) ReferenceError: exports is not defined
    at node_modules/@square/svelte-store/lib/index.js (index.ts:327:14)
    at __init (chunk-M5PF3ZFT.js?v=e2583755:25:56)
    at dep:@square_svelte-store:1:16

The dep:@square_svelte-store:1:16 file seems to be generated by Vite and contains export default require("./node_modules/@square/svelte-store/lib/index.js");.

I can't seem to figure out why this happens.

Dang. Would you be able to to create a minimal repro repo like kuechlerm did?

SarcevicAntonio commented 2 years ago

I can try, but it might take me till monday.

Akolyte01 commented 2 years ago

Totally, this is non urgent

SarcevicAntonio commented 2 years ago

Repro didn't produce any errors. Works as expeceted.

I then tried to get my project to break again, but it now works fine. 😅

It might have been, that some .svelte-kit/ or vite stuff was still stale... Sorry for the confusion.

Akolyte01 commented 2 years ago

Okay great to know, thanks for confirming :)