braze-inc / braze-web-sdk

Public repo for the Braze Web SDK
https://www.braze.com
Other
71 stars 25 forks source link

[Bug]: Cannot import individual modules #116

Closed DenizKucukozturk closed 2 years ago

DenizKucukozturk commented 2 years ago

Braze Web SDK Version

4.0.0

Integration Method

NPM

Browser

Chrome

Steps To Reproduce

I am using React with Next.js. When trying to do an partial import such as

import { changeUser } from "@braze/web-sdk";

I get the error:

/development/web/node_modules/@braze/web-sdk/src/index.js:1
export*from"./Card/index.js";export*from"./ContentCards/index.js";export*from"./Core/index.js";export*from"./Feed/index.js";export*from"./InAppMessage/index.js";export*from"./Push/index.js";export*from"./User/index.js";export{WindowUtils}from"./util/window-utils.js";

SyntaxError: Unexpected token 'export'
at wrapSafe (internal/modules/cjs/loader.js:988:16)
at Module._compile (internal/modules/cjs/loader.js:1036:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.@braze/web-sdk (/development/web/.next/server/pages/404.js:1307:18)
at __webpack_require__ (/development/web/.next/server/webpack-runtime.js:33:42)
at eval (webpack-internal:///./components/common/useSession.js:11:72)

Expected Behavior

I expected a successful partial import.

Actual Incorrect Behavior

Got the error SyntaxError: Unexpected token 'export'

Verbose Logs

No response

Additional Information

No response

wtfluckey commented 2 years ago

Same here.

Although, I am also getting this same error when trying to import the entire package as it says to do so in the docs.

import * as braze from "@braze/web-sdk";

^ returns the same Unexpected token 'export' error.

wesleyorbin commented 2 years ago

It looks like we need to add "type": "module" to our package.json for Next.js to recognize the SDK as ES Modules. We should have a fix out for this soon.

@wtfluckey Can you confirm that you're also using Next.js?

wtfluckey commented 2 years ago

Yes, I am using Next.js.

wesleyorbin commented 2 years ago

Hi @DenizKucukozturk @wtfluckey. We just released 4.0.1, which adds "type": "module" to the package.json. I'm going to close out the issue, but feel free to to re-open or file another issue if you continue to encounter issues.

wtfluckey commented 2 years ago

@wesleyorbin Thank you so much for the quick fix! I have tried version 4.0.1 and it does seem to fix the Unexpected token 'export' error. However, I am running into a new error, so I have created a new Github issue here: #117. Thanks for all your help!