Skip to content

Commit

Permalink
fix(csv-demo-ts-cjs-node16): upgrade module definition after latest t…
Browse files Browse the repository at this point in the history
…ypescript
  • Loading branch information
wdavidw committed Aug 25, 2023
1 parent b8df8db commit 87fe919
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 30 deletions.
4 changes: 2 additions & 2 deletions demo/cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion demo/eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
65 changes: 65 additions & 0 deletions demo/ts-cjs-node16/README.md
Original file line number Diff line number Diff line change
@@ -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
}
}
```
4 changes: 2 additions & 2 deletions demo/ts-cjs-node16/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -11,7 +11,7 @@
"license": "MIT",
"private": true,
"devDependencies": {
"typescript": "^5.1.6"
"typescript": "^5.2.2"
},
"scripts": {
"test": "tsc --noEmit"
Expand Down
4 changes: 2 additions & 2 deletions demo/ts-cjs-node16/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"esModuleInterop": true,
"module": "CommonJS",
"moduleResolution": "node16",
"module": "Node16",
"moduleResolution": "Node16",
"strict": true
}
}
4 changes: 2 additions & 2 deletions demo/ts-esm-node16/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion demo/webpack-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/csv-generate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
"author": "David Worms <david@adaltas.com> (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": {
".": {
Expand Down
8 changes: 4 additions & 4 deletions packages/csv-parse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions packages/csv-stringify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
"author": "David Worms <david@adaltas.com> (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",
"each": "^2.4.0",
"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": {
".": {
Expand Down
8 changes: 4 additions & 4 deletions packages/csv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions packages/stream-transform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
"author": "David Worms <david@adaltas.com> (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": {
".": {
Expand Down

0 comments on commit 87fe919

Please sign in to comment.