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

Build production using Vite React got error "Complex binding patterns require an initialization value" #283

Closed
lukenguyen-me opened this issue May 12, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@lukenguyen-me
Copy link

lukenguyen-me commented May 12, 2022

Describe the bug
Using ReactJS and Vite, the project works well when running as develop mode. But when build for production, I got the error

[commonjs] Complex binding patterns require an initialization value (14:6) in /Users/locnguyen/Documents/demo-near/node_modules/@near-wallet-selector/core/index.esm.js
file: /Users/locnguyen/Documents/demo-near/node_modules/@near-wallet-selector/core/index.esm.js:14:6
12:
13: // zloirock/core-js#86 (comment)
14: var global$I =
^
15: // eslint-disable-next-line es/no-global-this -- safe
16: check(typeof globalThis == 'object' && globalThis) ||

To Reproduce
I made a demo repository for reproducing here: https://github.com/phucloc8697/demo-near

  • After clone the repo, cd to demo-near, then yarn and yarn build

Expected behavior
The build should complete successfully with no error from near-wallet-selector.

Screenshots
Screen Shot 2022-05-12 at 10 46 28 AM

Device (please complete the following information):

  • OS: macOS 12.2.1
  • Yarn 1.22.190
  • Nodded 16.13.1
@lukenguyen-me lukenguyen-me added the bug Something isn't working label May 12, 2022
@kujtimprenkuSQA
Copy link
Contributor

Hey @phucloc8697 , thanks for raising this issue!

After some investigation the issue seems to be caused by the global: {} property in vite.config.ts.

To avoid getting build errors in this case you will need to change it slightly:

export default defineConfig({
  plugins: [react()],
  define: {
    "global": "window",
    "process.env.NODE_DEBUG": JSON.stringify(""),
  },
})

As suggested here: daily-co/daily-js#163 (comment)

To demonstrate that build is working I have forked your repo and then published it in gh-pages:

Forked repo: https://github.com/kujtimprenkuSQA/demo-near
Demo: https://kujtimprenkusqa.github.io/demo-near/

If you have any questions please let us know.

@lukenguyen-me
Copy link
Author

This worked for me. Thanks @kujtimprenkuSQA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants