SyntaxError: Unexpected token 'with'
Bug Report
Describe the bug
Getting the following error in Node v20:
file:///yahooFinance/node_modules/yahoo-finance2/dist/esm/src/lib/validateAndCoerceTypes.js:3
import pkg from "../../package.json" with { type: "json" };
^^^^
SyntaxError: Unexpected token 'with'
at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:118:18)
at callTranslator (node:internal/modules/esm/loader:273:14)
at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:30)
Node.js v20.9.0
Minimal Reproduction
Run the following using Node v20:
import yahooFinance from 'yahoo-finance2';
const results = await yahooFinance.quoteSummary('NVDA');
console.log(results);
Environment
Browser or Node: Node
Node version (if applicable): v20.9.0
Npm version: 10.1.0
Browser verion (if applicable): N/A
Library version (e.g. 1.10.1): 2.13.2
Additional Context
Looks like this is related to #800; Node v22 uses with but v20 uses assert?
Hey @wrrnlim, thanks for the report and for your patience. Slowly catching up on my backlog.
However, you did actually correctly report the related issue. This was a bit of bad planning on the node team's part, because, there was no overlap or grace time, you had to choose one or the other (one version would crash, and the other would work). So we used assert for v20 for a while and eventually switched to with for v22, once node v20 ended it's "active" version period.
Usually we would have supported v20 throughout it's maintenance period too, but in this case, we had to choose one or the other (or publish two separate versions of yahoo-finance, which is beyond the capabilities of our small team, unfortunately).