Skip to content

Fix "Cannot use import statement outside a module" #594

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

Merged
merged 2 commits into from
Apr 12, 2021

Conversation

vegardlarsen
Copy link
Contributor

Using HamburgerMenu from a SvelteKit project would result in the following error:

4:01:51 PM [vite] Error when evaluating SSR module /node_modules/carbon-components-svelte/src/UIShell/SideNav/HamburgerMenu.svelte:
/home/vegard/beat/backoffice-sapper/node_modules/carbon-icons-svelte/lib/Close20/index.js:1
import Close20 from "./Close20.svelte";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1101:16)
    at Module._compile (internal/modules/cjs/loader.js:1149:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
    at Module.load (internal/modules/cjs/loader.js:1034:32)
    at Function.Module._load (internal/modules/cjs/loader.js:923:14)
    at Module.require (internal/modules/cjs/loader.js:1074:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at nodeRequire (/home/vegard/beat/backoffice-sapper/node_modules/vite/dist/node/chunks/dep-66eb515d.js:69044:17)
    at ssrImport (/home/vegard/beat/backoffice-sapper/node_modules/vite/dist/node/chunks/dep-66eb515d.js:69002:20)
    at eval (/node_modules/carbon-components-svelte/src/UIShell/SideNav/HamburgerMenu.svelte:7:31) (x3)

To fix it, we need to reference the .svelte files for the icons.

Using `HamburgerMenu` from a SvelteKit project would result in the following error:

```
4:01:51 PM [vite] Error when evaluating SSR module /node_modules/carbon-components-svelte/src/UIShell/SideNav/HamburgerMenu.svelte:
/home/vegard/beat/backoffice-sapper/node_modules/carbon-icons-svelte/lib/Close20/index.js:1
import Close20 from "./Close20.svelte";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1101:16)
    at Module._compile (internal/modules/cjs/loader.js:1149:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
    at Module.load (internal/modules/cjs/loader.js:1034:32)
    at Function.Module._load (internal/modules/cjs/loader.js:923:14)
    at Module.require (internal/modules/cjs/loader.js:1074:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at nodeRequire (/home/vegard/beat/backoffice-sapper/node_modules/vite/dist/node/chunks/dep-66eb515d.js:69044:17)
    at ssrImport (/home/vegard/beat/backoffice-sapper/node_modules/vite/dist/node/chunks/dep-66eb515d.js:69002:20)
    at eval (/node_modules/carbon-components-svelte/src/UIShell/SideNav/HamburgerMenu.svelte:7:31) (x3)
```

To fix it, we need to reference the `.svelte` files for the icons.
@vercel
Copy link

vercel bot commented Apr 9, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/carbon-svelte/carbon-components-svelte/3LQQtWrMTKQGc3L7Yg2bakF8XSry
✅ Preview: https://carbon-compone-git-fork-vegardlarsen-patch-1-carbon-11d682.vercel.app

@metonym
Copy link
Collaborator

metonym commented Apr 11, 2021

Can you provide a code example so that I can reproduce it?

@vegardlarsen
Copy link
Contributor Author

Thank you for considering this. I initially tried to create a minimal reproduction of this issue, but I wasn't able to reproduce this when starting from scratch. So instead I started from my project (which I can't share in its entirety) and removed anything identifiable.

I created an archive with the contents of that reproduction here.

$ npm install && npm run dev -- --open

You should see the error immediately upon navigating to the project.

There seems to be something specifically with this project that causes the issue. If I start from scratch, and copy the src folder from that project over, the issue does not occur. I don't understand why at this point, but this will probably be my fix for this issue.

@metonym metonym merged commit 93f14c9 into carbon-design-system:master Apr 12, 2021
@metonym metonym mentioned this pull request Apr 14, 2021
@metonym
Copy link
Collaborator

metonym commented Apr 24, 2021

Published to NPM in version v0.32.2

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

Successfully merging this pull request may close these issues.

2 participants