Skip to content

SSR error - "SyntaxError: Unexpected token 'export'" with @vue/[email protected] #1469

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

Closed
bryanpackman opened this issue Apr 1, 2023 · 4 comments

Comments

@bryanpackman
Copy link

bryanpackman commented Apr 1, 2023

Describe the bug
I get the following error message in the node environment with @vue/[email protected]

(node:70395) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
12:02:02 PM [vite] Error when evaluating SSR module /src/apollo/apollo.ts: failed to import "@vue/apollo-option"

12:02:02 PM [vite] Error when evaluating SSR module /src/apollo/main.ts:

12:02:02 PM [vite] Error when evaluating SSR module /src/apollo/entry-server.ts:

/Users/packman/code/behance/sandbox/gql-cache-prototypes/node_modules/@vue/apollo-option/dist/vue-apollo-option.esm.js:1500
export { ApolloProvider, createApolloProvider };
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1195:20)
    at Module._compile (node:internal/modules/cjs/loader:1239:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
    at Module.load (node:internal/modules/cjs/loader:1133:32)
    at Module._load (node:internal/modules/cjs/loader:972:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:168:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)

This bug only happens on 4.0.0-beta.4. It works fine on 4.0.0-beta.2

Versions
vue: 3.2.47
@vue/apollo-option: 4.0.0-beta.4,
@apollo/client: 3.7.11

Additional Context
I am importing entry-server.ts with vite.ssrLoadModule

@bryanpackman
Copy link
Author

This error also happens with @vue/[email protected]

@Olli1080
Copy link

Olli1080 commented Apr 3, 2023

Workaround that works for me is to insert "type": "module" into the package.json and prefixing the exports with "./"

...
"type": "module",
"exports": {
    ".": {
      "types": "./dist/esm/index.d.ts",
      "import": "./dist/esm/index.js",
      "require": "./dist/cjs/index.js"
    },
    "./*": "./*"
  },
...

Also changeing from
import * as serializeJs from 'serialize-javascript';
to
import serializeJs from 'serialize-javascript';
in the esm/index.js

@itpropro
Copy link

Is there a fix planned for the next beta-5, rc or major release @Akryum ?

@Akryum Akryum closed this as completed in 2f4c6c3 May 16, 2023
@raymondtri
Copy link

I'm still experiencing issues directly related to esm imports with this package. It seems to only work when the steps above (#1469 (comment)) are manually changed in node_modules.

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

4 participants