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

Cannot assign to read only property 'compressed' of object '[object Module]' #140

Open
riderx opened this issue Oct 31, 2021 · 4 comments
Open
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@riderx
Copy link

riderx commented Oct 31, 2021

When build with vite and typescript in dev it work, but build in prod it show this error

@riderx
Copy link
Author

riderx commented Nov 1, 2021

let emojiIndex = new EmojiIndex(JSON.parse(JSON.stringify(dataEmoji))); temporary fix the issue

@serebrov
Copy link
Owner

serebrov commented Nov 4, 2021

@riderx Thanks for the report and the workaround, but I need some demo code to reproduce the issue.

Is your project open source (could you send a link in that case)? If not, it would be good to have some demo project where this issue is reproduced.

@serebrov serebrov added bug Something isn't working help wanted Extra attention is needed labels Nov 4, 2021
@riderx
Copy link
Author

riderx commented Nov 4, 2021

@serebrov here you go, the exemple fail but if you uncomment the second line it work
https://stackblitz.com/edit/vue3-ts?devtoolsheight=33&file=src/App.vue

@serebrov
Copy link
Owner

@riderx Looks like something goes wrong with the json import in this setup.

The imported json ends up being Module and not an Object:

console.log(dataEmoji)
> Module
> aliases: (...)
> categories: (...)
> compressed: true
> default: (...)
> emojis: (...)
> __esModule: true
> ...

console.log(JSON.parse(JSON.stringify(dataEmoji)))
> App.vue?037b:8 Object
> Object
> aliases: {raised_hand: 'hand', satisfied: 'laughing', …}
> categories: (9) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
> compressed: true
> ...

I do not see why exactly it does not work - vue cli (and webpack) should be able to handle this by default.

The other fix I found is to use require instead of import:

/* import * as dataEmoji from 'emoji-mart-vue-fast/data/twitter.json' */

/* eslint-disable @typescript-eslint/no-var-requires */
const dataEmoji = require('emoji-mart-vue-fast/data/twitter.json')

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

No branches or pull requests

2 participants