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

TypeError: Cannot create property 'lineStyle' on boolean 'false' #9430

Closed
7 tasks done
xbzhang2020 opened this issue Jul 29, 2022 · 2 comments · Fixed by #9454
Closed
7 tasks done

TypeError: Cannot create property 'lineStyle' on boolean 'false' #9430

xbzhang2020 opened this issue Jul 29, 2022 · 2 comments · Fixed by #9454
Labels
wontfix This will not be worked on

Comments

@xbzhang2020
Copy link

Describe the bug

When I migrate my project from vue-cli to vite,I encounter some problems, like that:

error

I find out that the problem comes from code like that:

var toolip = {
  crosshairs: false,
};

toolip.crosshairs['lineStyle'] = {}

Though it is unprecise, the code can run rightly in browser and node:

截屏2022-07-29 15 19 49

截屏2022-07-29 15 20 24

Why vite throw TypeError? The code comes from a third-party library,so I'm not able to modify it. Coluld vite svole the problem? Thanks.

Reproduction

https://stackblitz.com/edit/vitejs-vite-ugzs6j?file=main.js

System Info

System:
    OS: macOS 12.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 29.70 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.6.1 - ~/.nvm/versions/node/v16.6.1/bin/node
    Yarn: 1.22.11 - ~/.nvm/versions/node/v16.6.1/bin/yarn
    npm: 7.20.3 - ~/.nvm/versions/node/v16.6.1/bin/npm
    Watchman: 2021.06.07.00 - /usr/local/bin/watchman
  Browsers:
    Chrome: 103.0.5060.134
    Edge: 103.0.1264.77
    Firefox: 103.0
    Safari: 15.5
  npmPackages:
    @vitejs/plugin-vue: ^2.0.0 => 2.3.3 
    vite: ^2.7.2 => 2.9.14

Used Package Manager

yarn

Logs

No response

Validations

@sapphi-red
Copy link
Member

This is because your code does not work in strict mode. Also it is always strict mode inside ESM.
You could run the following code in devtools or rename src/test.js to src/test.mjs to reproduce it.

function f() {
    "use strict";
    var toolip = {
      crosshairs: false,
    };
    
    toolip.crosshairs['lineStyle'] = {};
    console.log(toolip);
}
f()

Since Vite outputs with ESM, I think this cannot be supported.

For a workaround, I think patch-package or pnpm patch could be used.

@xbzhang2020
Copy link
Author

Ohh! I get it. Thank you very much.

@sapphi-red sapphi-red added wontfix This will not be worked on and removed pending triage labels Jul 30, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Aug 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
wontfix This will not be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants