question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

D3: Cannot use import statement outside a module

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
benmccanncommented, Jan 31, 2022

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!

0reactions
arackafcommented, Dec 10, 2022

@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

image

Versions I’m using

"d3-array": "1.2.0",
"d3-axis": "1.0.8",
"d3-scale": "1.0.6",
"d3-selection": "1.1.0",
"d3-transition": "1.1.0",

Just an fyi, if it helps ya’ll

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found