nodejs / import-in-the-middle

Like `require-in-the-middle`, but for ESM import
https://www.npmjs.com/package/import-in-the-middle
Apache License 2.0
52 stars 20 forks source link

SyntaxError when importing a JSON file using { type: 'json' } #110

Closed inaiat closed 1 week ago

inaiat commented 2 weeks ago

Expected Behavior

The import statement should successfully import the JSON file.

Actual Behavior

A "SyntaxError" is thrown.

Steps to Reproduce the Problem

  1. Import json file using with specific syntax ( with { type: 'json'} ): import data from './data.json' with { type: 'json' };
  2. So I updated import-in-the-middle to 1.8.0 (Note that this works fine on version 1.7.3)
  3. After running project I gettting this error: { "type": "SyntaxError", "message": "Unexpected token (1:818) at SyntaxError: Unexpected token (1:818)", "stack": SyntaxError: Unexpected token (1:818) at pp$4.raise (/Users/inaiat/app/node_modules/.pnpm/acorn@8.12.0/node_modules/acorn/dist/acorn.js:3586:15) at pp$9.unexpected (/Users/inaiat/app/node_modules/.pnpm/acorn@8.12.0/node_modules/acorn/dist/acorn.js:772:10) at pp$9.semicolon (/Users/inaiat/app/node_modules/.pnpm/acorn@8.12.0/node_modules/acorn/dist/acorn.js:749:68) at Parser.parseImport (/Users/inaiat/app/node_modules/.pnpm/acorn-import-attributes@1.9.5_acorn@8.12.0/node_modules/acorn-import-attributes/lib/index.js:242:12) at pp$8.parseStatement (/Users/inaiat/app/node_modules/.pnpm/acorn@8.12.0/node_modules/acorn/dist/acorn.js:948:51) at pp$8.parseTopLevel (/Users/inaiat/app/node_modules/.pnpm/acorn@8.12.0/node_modules/acorn/dist/acorn.js:829:23) at Parser.parse (/Users/inaiat/app/node_modules/.pnpm/acorn@8.12.0/node_modules/acorn/dist/acorn.js:601:17) at Function.parse (/Users/inaiat/app/node_modules/.pnpm/acorn@8.12.0/node_modules/acorn/dist/acorn.js:651:37) at getEsmExports (/Users/inaiat/app/node_modules/.pnpm/import-in-the-middle@1.8.0/node_modules/import-in-the-middle/lib/get-esm-exports.js:37:23) at getExports (/Users/inaiat/app/node_modules/.pnpm/import-in-the-middle@1.8.0/node_modules/import-in-the-middle/lib/get-exports.js:73:12) "pos": 818, "loc": { "line": 1, "column": 818 }, "raisedAt": 822 }

Specifications

timfish commented 2 weeks ago

This was fixed by #104

inaiat commented 2 weeks ago

@timfish Thanks!

timfish commented 1 week ago

This is a duplicate of #105 but #104 does help work around the issue