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

[Bug]: Package uses ESM syntax but does not declare in packjage.json (Breaks SSR) #36

Open
onezone-pete opened this issue Dec 1, 2023 · 0 comments

Comments

@onezone-pete
Copy link

What happened?

This package currently breaks when included on a project that utilises server-side rendering. For server-side rendering all web dependencies need to work both within a browser, but also when executed within node.js. Node.js expects packages that contain javascript formatted in ESM to declare so in their “package.json", by adding “type”: “module”.

The “onesignal-vue3” package contains javascript formatted in ESM, however does not declare this in the “package.json".

When executing, the following error is thrown.

failed to import "@onesignal/onesignal-vue3"
|- /Users/pete/code/onezone.vscode.workspace/onezone.client/node_modules/@onesignal/onesignal-vue3/dist/index.js:548
export const useOneSignal = () => {
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1084:15)
    at Module._compile (node:internal/modules/cjs/loader:1119:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:526:24)

What browsers are you seeing the problem on?

Other

What operating system are you running?

n/a

Steps to reproduce?

1. Add package to a web project that utilises server-side rendering
2. Execute web project

What did you expect to happen?

For the execution to be successful and no error to be thrown

Relevant log output

failed to import "@onesignal/onesignal-vue3"
|- /Users/pete/code/onezone.vscode.workspace/onezone.client/node_modules/@onesignal/onesignal-vue3/dist/index.js:548
export const useOneSignal = () => {
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1084:15)
    at Module._compile (node:internal/modules/cjs/loader:1119:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:526:24)
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

1 participant