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

SyntaxError: Cannot use import statement outside a module after yarn3 #2393

Closed
erg opened this issue Sep 8, 2021 · 1 comment
Closed

SyntaxError: Cannot use import statement outside a module after yarn3 #2393

erg opened this issue Sep 8, 2021 · 1 comment

Comments

@erg
Copy link

erg commented Sep 8, 2021

Describe the bug

There's an import error on startup after npm init svelte@next and yarn run dev with yarn3.

This looks like the same error message as #2161 but the issue seems different. I hope this is the correct repository for reporting this issue.

Reproduction

Commands without output (except the last):

(base) ➜  npm init svelte@next my-app                                 
(base) ➜  cd my-app 
(base) ➜  my-app yarn set version berry    
(base) ➜  my-app yarn
/home/erg/my-app/.yarn/__virtual__/@sveltejs-kit-virtual-e79fbd740b/0/cache/@sveltejs-kit-npm-1.0.0-next.165-3f2325a2a6-6fd796f1e6.zip/node_modules/@sveltejs/kit/svelte-kit.js:2
import './dist/cli.js';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.external_module_.Module._load (/home/erg/my-app/.pnp.cjs:10817:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at node:internal/main/run_main_module:17:47

Logs

Initial command:

# Answer defaults to the npm init questions (no/no/no/no)
(base) ➜  ~ npm init svelte@next my-app                                 
create-svelte version 2.0.0-next.78

Welcome to SvelteKit!

This is beta software; expect bugs and missing features.

If you encounter a problem, open an issue on https://github.com/sveltejs/kit/issues if none exists already.

✔ Which Svelte app template? › SvelteKit demo app
✔ Use TypeScript? … No / Yes
✔ Add ESLint for code linting? … No / Yes
✔ Add Prettier for code formatting? … No / Yes
✔ Copied project files

Want to add other parts to your code base? Visit https://github.com/svelte-add/svelte-adders, a community project of commands to add particular functionality to Svelte projects


Next steps:
  1: cd my-app
  2: npm install (or pnpm install, etc)
  3: git init && git add -A && git commit -m "Initial commit" (optional step)
  4: npm run dev -- --open

To close the dev server, hit Ctrl-C

Stuck? Visit us at https://svelte.dev/chat

Next command:

(base) ➜  ~ cd my-app 
(base) ➜  my-app yarn set version berry    
warning package.json: No license field
Resolving berry to a url...
Downloading https://github.com/yarnpkg/berry/raw/master/packages/berry-cli/bin/berry.js...
Saving it into /home/erg/my-app/.yarn/releases/yarn-berry.cjs...
Updating /home/erg/my-app/.yarnrc.yml...
Done!

(base) ➜  my-app yarn
➤ YN0000: ┌ Resolution step
yarn run de➤ YN0032: │ fsevents@npm:2.3.2: Implicit dependencies on node-gyp are discouraged
➤ YN0032: │ fsevents@npm:2.3.2: Implicit dependencies on node-gyp are discouraged
v
➤ YN0000: └ Completed in 2s 505ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ vite@npm:2.5.6 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ which@npm:2.0.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wide-align@npm:1.1.3 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wrappy@npm:1.0.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yallist@npm:4.0.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed in 0s 274ms
➤ YN0000: ┌ Link step
➤ YN0007: │ esbuild@npm:0.12.25 must be built because it never has been before or the last one failed
➤ YN0000: └ Completed in 0s 211ms
➤ YN0000: Done with warnings in 3s 10ms
(base) ➜  my-app yarn run dev
/home/erg/my-app/.yarn/__virtual__/@sveltejs-kit-virtual-e79fbd740b/0/cache/@sveltejs-kit-npm-1.0.0-next.165-3f2325a2a6-6fd796f1e6.zip/node_modules/@sveltejs/kit/svelte-kit.js:2
import './dist/cli.js';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.external_module_.Module._load (/home/erg/my-app/.pnp.cjs:10817:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at node:internal/main/run_main_module:17:47


### System Info

```shell
(base) ➜  ~ npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"



  System:
    OS: Linux 5.11 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (16) x64 Intel(R) Xeon(R) W-11955M CPU @ 2.60GHz
    Memory: 95.86 GB / 125.03 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 16.7.0 - ~/.nvm/versions/node/v16.7.0/bin/node
    Yarn: 1.22.11 - ~/.nvm/versions/node/v16.7.0/bin/yarn
    npm: 7.22.0 - ~/.nvm/versions/node/v16.7.0/bin/npm
  Browsers:
    Chrome: 93.0.4577.63
    Chromium: 93.0.4577.63
    Firefox: 91.0.2

After setting yarn to berry:

yarn --version
3.0.2


### Severity

serious, but I can work around it

### Additional Information

If I use npm or yarn1 then it works, even if I go to yarn3 afterwards.
@Conduitry
Copy link
Member

https://kit.svelte.dev/faq#how-do-i-use-x-with-sveltekit-does-it-work-with-yarn-2

Yarn's PnP mode isn't supported because it doesn't yet support ESM.

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

No branches or pull requests

2 participants