You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Node v18 with ESM and --experimental-json-modules flag active in order to use the import assertion for JSON files like this:
import genericERC20 from '../json/FILE.json' assert {type: "json"};
With Yarn v3.2.2 (Zero Install, PNP) I get this error:
Error: Unknown file extension ".json" for /Users/samuelexferri/GITHUB/PROJECT/dist/json/FILE.json
Solutions?
To reproduce
I'm trying to import into a .ts file a json file using Node v18 and --experimental-json-modules flag like this:
import genericERC20 from '../abi/GenericERC20.json' assert {type: "json"};
But when I try to run the script, I obtain this error:
You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
Error: Unknown file extension ".json" for /Users/samuelexferri/GITHUB/PROJECT/dist/json/FILE.json
at getFileFormat (file:///Users/samuelexferri/GITHUB/PROJECT/.pnp.loader.mjs:129:13)
at load$1 (file:///Users/samuelexferri/GitHub/PROJECT.pnp.loader.mjs:177:18)
at ESMLoader.load (node:internal/modules/esm/loader:431:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:350:22)
at new ModuleJob (node:internal/modules/esm/module_job:66:26)
at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:369:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:328:34)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:82:21)
at async Promise.all (index 3)
at link (node:internal/modules/esm/module_job:87:9)
So I cannot import a JSON file through the .pnp.loader.mjs.
I run the script with NO ISSUES (so JSON correctly imported) deleting lines 128:130 of .pnp.loader.mjs but every time I will run yarn install I will need to remove these lines again.
case `.json`: {
throw new Error(`Unknown file extension ".json" for ${filepath}`);
}
Self-service
Describe the bug
I'm using Node v18 with ESM and
--experimental-json-modules
flag active in order to use the import assertion for JSON files like this:With Yarn v3.2.2 (Zero Install, PNP) I get this error:
Solutions?
To reproduce
I'm trying to import into a
.ts
file ajson
file using Node v18 and--experimental-json-modules
flag like this:But when I try to run the script, I obtain this error:
So I cannot import a JSON file through the
.pnp.loader.mjs
.I run the script with NO ISSUES (so JSON correctly imported) deleting lines 128:130 of
.pnp.loader.mjs
but every time I will runyarn install
I will need to remove these lines again.Environment
System: OS: macOS 12.4 CPU: (10) arm64 Apple M1 Pro Binaries: Node: 18.2.0 - /private/var/folders/0n/cdtksrxx2cj3zvnnq066_hvh0000gn/T/xfs-55b42ae9/node Yarn: 3.2.2 - /private/var/folders/0n/cdtksrxx2cj3zvnnq066_hvh0000gn/T/xfs-55b42ae9/yarn npm: 8.9.0 - ~/.nvm/versions/node/v18.2.0/bin/npm
Additional context
My
.yarnrc
:My
.tsconfig
:The text was updated successfully, but these errors were encountered: