Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.ts(1343)

I keep getting "The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.ts(1343)" when trying to use import.meta.url (as shown in Parcel docs). Yes, I have configured my tsconfig as suggested in the message (tried all 3 options).

I'm trying to dynamically load images from an assets folder using React, Typescript and Parcel 2. I have scoured the internet searching for solutions and I've read about merging and augmenting types in Typescript, but I can't seem to make it work.

like image 981
yesenia Avatar asked Oct 26 '21 00:10

yesenia


2 Answers

If you are using VSCode and you have the module setting in typescript configuration set to 'es2020', 'es2022', 'esnext', 'system', 'node12', or 'nodenext'.

Then you might want to try simply restarting your typescript server. The quickest way would by hitting (ctrl+shift+p) and selecting restart typescript server. Picture attached.

restart typescript server

like image 160
Michael Sorensen Avatar answered Oct 17 '22 11:10

Michael Sorensen


// tsconfig.json
{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    ...
like image 22
Barış Şenyerli Avatar answered Oct 17 '22 11:10

Barış Şenyerli