diff --git a/demo/cjs/package.json b/demo/cjs/package.json index a0521411..ceebcc25 100644 --- a/demo/cjs/package.json +++ b/demo/cjs/package.json @@ -11,12 +11,12 @@ "csv-stringify": "^6.4.1" }, "devDependencies": { - "@types/node": "^20.5.0", + "@types/node": "^20.5.6", "coffeescript": "^2.7.0", "mocha": "^10.2.0", "should": "^13.2.3", "ts-node": "^10.9.1", - "typescript": "^5.1.6" + "typescript": "^5.2.2" }, "mocha": { "inline-diffs": true, diff --git a/demo/eslint/package.json b/demo/eslint/package.json index 6abfe692..35355277 100644 --- a/demo/eslint/package.json +++ b/demo/eslint/package.json @@ -15,6 +15,6 @@ "devDependencies": { "eslint": "^8.47.0", "eslint-config-airbnb-base": "^15.0.0", - "eslint-plugin-import": "^2.28.0" + "eslint-plugin-import": "^2.28.1" } } diff --git a/demo/ts-cjs-node16/README.md b/demo/ts-cjs-node16/README.md new file mode 100644 index 00000000..45a203e3 --- /dev/null +++ b/demo/ts-cjs-node16/README.md @@ -0,0 +1,65 @@ + +# TypeScript with CommonJS and moduleresolution set to node16 + +This demo is created after issue #354. The package is defined as CommonJS. The code, written in TypeScript, import each CSV packages, for example with `import { parse, Parser } from 'csv-parse';`. + +## Original error + +The original issue describes how TypeScript failed to import from a CommonJS package. For example with `tsc`: + +```bash +$ tsc +main.ts:1:23 - error TS1471: Module 'csv-parse' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. + +1 import { parse } from 'csv-parse'; + ~~~~~~~~~~~ + + +Found 1 error in main.ts:1 +``` + +To fix this, the demo used the following `tsconfig.json` file: + +```json +{ + "compilerOptions": { + "esModuleInterop": true, + "module": "CommonJS", + "moduleResolution": "node16", + "strict": true + } +} +``` + +## Second error + +After the upgrade of TypeScript from version `^5.1.6` to `^5.2.2`, a new error is thrown: + +```bash +$ yarn test +yarn run v1.22.19 +$ tsc --noEmit +tsconfig.json:4:15 - error TS5110: Option 'module' must be set to 'Node16' when option 'moduleResolution' is set to 'Node16'. + +4 "module": "CommonJS", + ~~~~~~~~~~ + + +Found 1 error in tsconfig.json:4 + +error Command failed with exit code 2. +``` + + +To fix this, the demo now uses the following `tsconfig.json` file: + +```json +{ + "compilerOptions": { + "esModuleInterop": true, + "module": "node16", + "moduleResolution": "node16", + "strict": true + } +} +``` diff --git a/demo/ts-cjs-node16/package.json b/demo/ts-cjs-node16/package.json index ac2fa46c..b968aae9 100644 --- a/demo/ts-cjs-node16/package.json +++ b/demo/ts-cjs-node16/package.json @@ -1,5 +1,5 @@ { - "name": "csv-demo-ts-moduleresolution-node16-cjs", + "name": "csv-demo-ts-cjs-node16", "version": "0.2.10", "dependencies": { "csv-generate": "^4.2.7", @@ -11,7 +11,7 @@ "license": "MIT", "private": true, "devDependencies": { - "typescript": "^5.1.6" + "typescript": "^5.2.2" }, "scripts": { "test": "tsc --noEmit" diff --git a/demo/ts-cjs-node16/tsconfig.json b/demo/ts-cjs-node16/tsconfig.json index 79bbae71..1f403e45 100644 --- a/demo/ts-cjs-node16/tsconfig.json +++ b/demo/ts-cjs-node16/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { "esModuleInterop": true, - "module": "CommonJS", - "moduleResolution": "node16", + "module": "Node16", + "moduleResolution": "Node16", "strict": true } } diff --git a/demo/ts-esm-node16/package.json b/demo/ts-esm-node16/package.json index 0aa69afd..d4f7ef5e 100644 --- a/demo/ts-esm-node16/package.json +++ b/demo/ts-esm-node16/package.json @@ -12,12 +12,12 @@ "stream-transform": "^3.2.7" }, "devDependencies": { - "@types/node": "^20.5.0", + "@types/node": "^20.5.6", "coffeescript": "^2.7.0", "mocha": "^10.2.0", "should": "^13.2.3", "ts-node": "^10.9.1", - "typescript": "^5.1.6" + "typescript": "^5.2.2" }, "mocha": { "inline-diffs": true, diff --git a/demo/webpack-ts/package.json b/demo/webpack-ts/package.json index 841e6cb2..ab362f42 100644 --- a/demo/webpack-ts/package.json +++ b/demo/webpack-ts/package.json @@ -18,7 +18,7 @@ "node-polyfill-webpack-plugin": "^2.0.1", "stream-browserify": "^3.0.0", "ts-loader": "^9.4.4", - "typescript": "^5.1.6", + "typescript": "^5.2.2", "webpack": "^5.88.2", "webpack-cli": "^5.1.4" }, diff --git a/packages/csv-generate/package.json b/packages/csv-generate/package.json index 9d0acba2..39d6435d 100644 --- a/packages/csv-generate/package.json +++ b/packages/csv-generate/package.json @@ -12,20 +12,20 @@ "author": "David Worms (https://www.adaltas.com)", "devDependencies": { "@rollup/plugin-eslint": "^9.0.4", - "@rollup/plugin-node-resolve": "^15.1.0", + "@rollup/plugin-node-resolve": "^15.2.1", "@types/mocha": "^10.0.1", - "@types/node": "^20.5.0", + "@types/node": "^20.5.6", "@types/should": "^13.0.0", "coffeescript": "~2.7.0", "each": "^2.4.0", "eslint": "^8.47.0", "mocha": "~10.2.0", - "rollup": "^3.28.0", + "rollup": "^3.28.1", "rollup-plugin-node-builtins": "^2.1.2", "rollup-plugin-node-globals": "^1.4.0", "should": "~13.2.3", "ts-node": "^10.9.1", - "typescript": "^5.1.6" + "typescript": "^5.2.2" }, "exports": { ".": { diff --git a/packages/csv-parse/package.json b/packages/csv-parse/package.json index 224e0d38..ca738e7f 100644 --- a/packages/csv-parse/package.json +++ b/packages/csv-parse/package.json @@ -61,9 +61,9 @@ }, "devDependencies": { "@rollup/plugin-eslint": "^9.0.4", - "@rollup/plugin-node-resolve": "^15.1.0", + "@rollup/plugin-node-resolve": "^15.2.1", "@types/mocha": "^10.0.1", - "@types/node": "^20.5.0", + "@types/node": "^20.5.6", "coffeelint": "^2.1.0", "coffeescript": "^2.7.0", "csv-generate": "^4.2.7", @@ -72,13 +72,13 @@ "eslint": "^8.47.0", "mocha": "^10.2.0", "pad": "^3.2.0", - "rollup": "^3.28.0", + "rollup": "^3.28.1", "rollup-plugin-node-builtins": "^2.1.2", "rollup-plugin-node-globals": "^1.4.0", "should": "^13.2.3", "stream-transform": "^3.2.7", "ts-node": "^10.9.1", - "typescript": "^5.1.6" + "typescript": "^5.2.2" }, "files": [ "dist", diff --git a/packages/csv-stringify/package.json b/packages/csv-stringify/package.json index 556115e8..43feb830 100644 --- a/packages/csv-stringify/package.json +++ b/packages/csv-stringify/package.json @@ -10,9 +10,9 @@ "author": "David Worms (https://www.adaltas.com)", "devDependencies": { "@rollup/plugin-eslint": "^9.0.4", - "@rollup/plugin-node-resolve": "^15.1.0", + "@rollup/plugin-node-resolve": "^15.2.1", "@types/mocha": "^10.0.1", - "@types/node": "^20.5.0", + "@types/node": "^20.5.6", "@types/should": "^13.0.0", "coffeescript": "~2.7.0", "csv-generate": "^4.2.7", @@ -20,12 +20,12 @@ "eslint": "^8.47.0", "express": "^4.18.2", "mocha": "~10.2.0", - "rollup": "^3.28.0", + "rollup": "^3.28.1", "rollup-plugin-node-builtins": "^2.1.2", "rollup-plugin-node-globals": "^1.4.0", "should": "~13.2.3", "ts-node": "^10.9.1", - "typescript": "^5.1.6" + "typescript": "^5.2.2" }, "exports": { ".": { diff --git a/packages/csv/package.json b/packages/csv/package.json index 55e6a265..9f2dd997 100644 --- a/packages/csv/package.json +++ b/packages/csv/package.json @@ -28,20 +28,20 @@ }, "devDependencies": { "@rollup/plugin-eslint": "^9.0.4", - "@rollup/plugin-node-resolve": "^15.1.0", + "@rollup/plugin-node-resolve": "^15.2.1", "@types/mocha": "^10.0.1", - "@types/node": "^20.5.0", + "@types/node": "^20.5.6", "@types/should": "^13.0.0", "coffeescript": "~2.7.0", "each": "^2.4.0", "eslint": "^8.47.0", "mocha": "~10.2.0", - "rollup": "^3.28.0", + "rollup": "^3.28.1", "rollup-plugin-node-builtins": "^2.1.2", "rollup-plugin-node-globals": "^1.4.0", "should": "~13.2.3", "ts-node": "^10.9.1", - "typescript": "^5.1.6" + "typescript": "^5.2.2" }, "engines": { "node": ">= 0.1.90" diff --git a/packages/stream-transform/package.json b/packages/stream-transform/package.json index 8f4b0045..a9971426 100644 --- a/packages/stream-transform/package.json +++ b/packages/stream-transform/package.json @@ -11,21 +11,21 @@ "author": "David Worms (https://www.adaltas.com)", "devDependencies": { "@rollup/plugin-eslint": "^9.0.4", - "@rollup/plugin-node-resolve": "^15.1.0", + "@rollup/plugin-node-resolve": "^15.2.1", "@types/mocha": "^10.0.1", - "@types/node": "^20.5.0", + "@types/node": "^20.5.6", "coffeescript": "~2.7.0", "csv-generate": "^4.2.7", "each": "^2.4.0", "eslint": "^8.47.0", "mocha": "~10.2.0", "pad": "~3.2.0", - "rollup": "^3.28.0", + "rollup": "^3.28.1", "rollup-plugin-node-builtins": "^2.1.2", "rollup-plugin-node-globals": "^1.4.0", "should": "~13.2.3", "ts-node": "^10.9.1", - "typescript": "^5.1.6" + "typescript": "^5.2.2" }, "exports": { ".": {