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

Error when evaluating SSR module (Unexpected token 'export') in DEV #2914

Closed
livehtml opened this issue Nov 25, 2021 · 7 comments · May be fixed by naiba4/kit#1
Closed

Error when evaluating SSR module (Unexpected token 'export') in DEV #2914

livehtml opened this issue Nov 25, 2021 · 7 comments · May be fixed by naiba4/kit#1
Labels
p3-edge-case SvelteKit cannot be used in an uncommon way vite

Comments

@livehtml
Copy link

livehtml commented Nov 25, 2021

Describe the bug

When I run pnpm run dev and load some page I've got an error in console:

3:53:23 PM [vite] Error when evaluating SSR module /.svelte-kit/dev/runtime/internal/singletons.js:
SyntaxError: Unexpected token 'export'
    at new AsyncFunction (<anonymous>)
    at instantiateModule (/home/www/sources/node_modules/.pnpm/vite@2.6.14_sass@1.43.5/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:66543:28)
3:53:23 PM [vite] Error when evaluating SSR module /.svelte-kit/dev/runtime/app/navigation.js:
SyntaxError: Unexpected token 'export'
    at new AsyncFunction (<anonymous>)
    at instantiateModule (/home/www/sources/node_modules/.pnpm/vite@2.6.14_sass@1.43.5/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:66543:28)
3:53:23 PM [vite] Error when evaluating SSR module /src/lib/Components/Base/LoginPopup.svelte:
SyntaxError: Unexpected token 'export'
    at new AsyncFunction (<anonymous>)
    at instantiateModule (/home/www/sources/node_modules/.pnpm/vite@2.6.14_sass@1.43.5/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:66543:28)
3:53:23 PM [vite] Error when evaluating SSR module /src/routes/__layout.svelte:
SyntaxError: Unexpected token 'export'
    at new AsyncFunction (<anonymous>)
    at instantiateModule (/home/www/sources/node_modules/.pnpm/vite@2.6.14_sass@1.43.5/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:66543:28)
Unexpected token 'export'
SyntaxError: Unexpected token 'export'
    at new AsyncFunction (<anonymous>)
    at instantiateModule (/home/www/sources/node_modules/.pnpm/vite@2.6.14_sass@1.43.5/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:66543:28)

But if I reload the page — no more errors until I again restart dev.

Reproduction

I can't tell exaclty why and when in happens, but looks like it's an error from packages. Probably after updating dependencies few days ago.

System Info

System:
    OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (2) x64 DO-Regular
    Memory: 249.28 MB / 3.84 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.13.0 - /usr/bin/node
    npm: 8.1.0 - /usr/bin/npm
  npmPackages:
    @sveltejs/adapter-node: ^1.0.0-next.55 => 1.0.0-next.55 
    @sveltejs/adapter-static: ^1.0.0-next.21 => 1.0.0-next.21 
    @sveltejs/kit: next => 1.0.0-next.200 
    svelte: ^3.44.2 => 3.44.2

Severity

serious, but I can work around it

Additional Information

No response

@bluwy
Copy link
Member

bluwy commented Nov 25, 2021

I created a skeleton app and run in dev but I'm not getting the errors. Please provide a reproduction so we can track this down. Thanks!

@livehtml
Copy link
Author

Sorry, it was my mistake. But the reason of this error output totally unclear. I've just put image with wrong path (missed file):
img(src="images/default-ava.svg", alt="ava")
(I'm using svelte preprocess Pug)

So, it's really strange error output. And there is even no file where I'm put this missed image. Totally confused 🤷‍♂️

@jrmoynihan
Copy link

Having the same types of issues here. Valid Vite imports of functions in my .ts files are just failing. Seems really random.

@dominikg
Copy link
Member

Without a proper reproduction there is nothing we can do to analyze this further. Please provide the required information.

@denizkenan
Copy link

@dominikg I have similar case here:

https://stackblitz.com/edit/sveltekit-oydoc5?file=src/lib/Chart.svelte

when used with cloudflare worker adapter build works without any issue. Dev mode throws same error mentioned in this issue.

@bluwy bluwy added p3-edge-case SvelteKit cannot be used in an uncommon way vite and removed pending clarification labels Jan 23, 2022
@Rich-Harris
Copy link
Member

The issue in the reproduction is caused by echarts exposing native JS modules without having "type": "module" in its package.json. This is a bug in that library; it should either add "type": "module" and use .cjs for the CommonJS files, or use .mjs for the modules. Either way, it should add an "exports" field to package.json. Otherwise, it won't work correctly in Node.

It can be worked around by including it in Vite's processing:

// svelte.config.js
export default {
  kit: {
    vite: {
      ssr: {
        noExternal: ['echarts']
      }
    }
  }
};

No idea what's going on with the original issue but since there's no repro there's no way for us to investigate — closing.

@csjh
Copy link

csjh commented Jul 15, 2022

The issue in the reproduction is caused by echarts exposing native JS modules without having "type": "module" in its package.json. This is a bug in that library; it should either add "type": "module" and use .cjs for the CommonJS files, or use .mjs for the modules. Either way, it should add an "exports" field to package.json. Otherwise, it won't work correctly in Node.

It can be worked around by including it in Vite's processing:

// svelte.config.js
export default {
  kit: {
    vite: {
      ssr: {
        noExternal: ['echarts']
      }
    }
  }
};

No idea what's going on with the original issue but since there's no repro there's no way for us to investigate — closing.

This workaround isn't working anymore after the switch to Vite 3, reproduction in https://github.com/csjh/broken_kit

Edit: fixed by putting ssr: { format: 'cjs' } in vite.config.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-edge-case SvelteKit cannot be used in an uncommon way vite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants