[Bug]: Package uses ESM syntax but does not declare in packjage.json (Breaks SSR)
Opened this issue · 0 comments
onezone-pete commented
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)