Question

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.

 48  51011  48
1 Jan 1970

Solution

 43

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

2022-04-04

Solution

 15
// tsconfig.json
{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    ...
2022-04-11