D3: Cannot use import statement outside a module
See original GitHub issueDescribe the bug
I’m using Sveltekit for the first time, and am trying to drop in the D3 example from
https://svelte.dev/repl/8722c32f4e1a44a98e3a3fc8a095b2d7?version=3.5.3
into the index.svelte file in the latest sveltkit bundle, but am getting
“Cannot use import statement outside a module” - What does this mean?
Reproduction
Starting anew:
npm init svelte@next itms-svelte && cd itms-svelte && npm install && npm run dev -- --open --port 3333
Then in index.svelte I copy/paste the d3 example:
https://svelte.dev/repl/8722c32f4e1a44a98e3a3fc8a095b2d7?version=3.5.3
And npm watch will refresh the UI on port 3333 to show noob error.
Logs
Cannot use import statement outside a module
/home/<my folder path>/postcss.config.js:1
import autoprefixer from 'autoprefixer';
^^^^^^
System Info
System:
OS: Linux 5.10 Ubuntu 18.04.5 LTS (Bionic Beaver)
CPU: (8) x64 Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz
Memory: 1.04 GB / 24.91 GB
Container: Yes
Shell: 5.4.2 - /usr/bin/zsh
Binaries:
Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.17
@sveltejs/kit: next => 1.0.0-next.247
svelte: ^3.44.0 => 3.46.3
Severity
blocking all usage of SvelteKit
Additional Information
Just the usual .js dependency woes and confusion.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
"Uncaught SyntaxError: Cannot use import statement outside ...
This means that you're using the native source code in an unaltered/unbundled state, leading to the following error: Uncaught SyntaxError: ...
Read more >Cannot use import statement outside module in JavaScript
The "SyntaxError: Cannot use import statement outside a module" occurs when we use the ES6 Modules syntax in a script that was not...
Read more >How to fix "cannot use import statement outside a module"
I stumbled on this error: Uncaught SyntaxError: cannot use import statement outside a module while importing a function from a JavaScript ...
Read more >SyntaxError: Cannot use import statement outside a module
This error is one of the most common issue if you are trying to use ES6 features in your JavaScript project. For eg:...
Read more >cannot use import statement outside a module - ItsMyCode
The Uncaught syntaxerror: cannot use import statement outside a module occurs if you have forgotten to add type="module" attribute while ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Would you mind pushing the code to a repository or https://sveltekit.new/ project? It will save us a bit of time in debugging this. Thanks!
@Rich-Harris I don’t know why I was doing this, or if this is the same problem OP was having, but this was the change needed to fix the issue I saw
Versions I’m using
Just an fyi, if it helps ya’ll