marker-io / browser-sdk

Marker.io browser SDK
MIT License
8 stars 8 forks source link

Unexpected token 'export' error when loading npm package in React project #13

Closed mikeybinns closed 1 year ago

mikeybinns commented 1 year ago

When loading the package from a Remix/React project, I'm running into this error: .../node_modules/@marker.io/browser/src/index.js:5

export default {
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1033:15)
    at Module._compile (node:internal/modules/cjs/loader:1069:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (.../app/root.tsx:12:23)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at .../node_modules/@remix-run/serve/dist/index.js:43:17

Looks like it's trying to load your esm package with the commonjs loader (node:internal/modules/cjs/loader), which leads to an error. A potential fix for this issue would be to add "type": "module", to the package.json so Node knows that it's an ESM package.

olivierkaisin commented 1 year ago

@mikeybinns Thanks for reporting, we've been working on a package rewrite that introduces support for both CommonJS and ESM modules. Could you give a try to the newly published version 0.13.0-beta.0?

olivierkaisin commented 1 year ago

Hi @mikeybinns, we released improvements in version 0.13.0, please try it out and let me know if it works.

mikeybinns commented 1 year ago

This appears to have worked, thanks :)