Skip to content

[Bug?]: PnP loader cannot handle jsons #4245

Closed
@espoal

Description

@espoal

Self-service

  • I'd be willing to implement a fix

Describe the bug

The pnp module loader seems incapable of loading jsons:

file:///home/mamluk/3pass/esm-pwa/.pnp.loader.mjs:125
      throw new Error(`Unknown file extension ".json" for ${filepath}`);
            ^

Error: Unknown file extension ".json" for /home/mamluk/3pass/esm-pwa/package.json
    at getFileFormat (file:///home/mamluk/3pass/esm-pwa/.pnp.loader.mjs:125:13)
    at load$1 (file:///home/mamluk/3pass/esm-pwa/.pnp.loader.mjs:174:18)
    at ESMLoader.load (node:internal/modules/esm/loader:407:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:326:22)
    at new ModuleJob (node:internal/modules/esm/module_job:66:26)
    at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:345:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:304:34)
    at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:82:21)
    at async Promise.all (index 2)
    at async link (node:internal/modules/esm/module_job:87:9)

Node.js v17.7.2

To reproduce

test.mjs

import pkg from './package.json' assert { type: 'json' }
console.log({version: pkg.version})

With node test.mjs I get:

node test.mjs 
{ version: '0.0.1' }
(node:60949) ExperimentalWarning: Importing JSON modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

With yarn node test.mjs I get the error.

Environment

System:
    OS: Linux 5.13 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor
  Binaries:
    Node: 17.7.2 - /tmp/xfs-68437570/node
    Yarn: 3.2.0 - /tmp/xfs-68437570/yarn
    npm: 8.5.2 - /usr/bin/npm

Additional context

My .yarnrc.yml is:

yarnPath: .yarn/releases/yarn-3.2.0.cjs

pnpEnableEsmLoader: true

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingesmupholdedReal issues without formal reproduction

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions