Skip to content

Commit 87fe919

Browse files
committedAug 25, 2023
fix(csv-demo-ts-cjs-node16): upgrade module definition after latest typescript
1 parent b8df8db commit 87fe919

File tree

12 files changed

+95
-30
lines changed

12 files changed

+95
-30
lines changed
 

‎demo/cjs/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
"csv-stringify": "^6.4.1"
1212
},
1313
"devDependencies": {
14-
"@types/node": "^20.5.0",
14+
"@types/node": "^20.5.6",
1515
"coffeescript": "^2.7.0",
1616
"mocha": "^10.2.0",
1717
"should": "^13.2.3",
1818
"ts-node": "^10.9.1",
19-
"typescript": "^5.1.6"
19+
"typescript": "^5.2.2"
2020
},
2121
"mocha": {
2222
"inline-diffs": true,

‎demo/eslint/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
"devDependencies": {
1616
"eslint": "^8.47.0",
1717
"eslint-config-airbnb-base": "^15.0.0",
18-
"eslint-plugin-import": "^2.28.0"
18+
"eslint-plugin-import": "^2.28.1"
1919
}
2020
}

‎demo/ts-cjs-node16/README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
# TypeScript with CommonJS and moduleresolution set to node16
3+
4+
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';`.
5+
6+
## Original error
7+
8+
The original issue describes how TypeScript failed to import from a CommonJS package. For example with `tsc`:
9+
10+
```bash
11+
$ tsc
12+
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.
13+
14+
1 import { parse } from 'csv-parse';
15+
~~~~~~~~~~~
16+
17+
18+
Found 1 error in main.ts:1
19+
```
20+
21+
To fix this, the demo used the following `tsconfig.json` file:
22+
23+
```json
24+
{
25+
"compilerOptions": {
26+
"esModuleInterop": true,
27+
"module": "CommonJS",
28+
"moduleResolution": "node16",
29+
"strict": true
30+
}
31+
}
32+
```
33+
34+
## Second error
35+
36+
After the upgrade of TypeScript from version `^5.1.6` to `^5.2.2`, a new error is thrown:
37+
38+
```bash
39+
$ yarn test
40+
yarn run v1.22.19
41+
$ tsc --noEmit
42+
tsconfig.json:4:15 - error TS5110: Option 'module' must be set to 'Node16' when option 'moduleResolution' is set to 'Node16'.
43+
44+
4 "module": "CommonJS",
45+
~~~~~~~~~~
46+
47+
48+
Found 1 error in tsconfig.json:4
49+
50+
error Command failed with exit code 2.
51+
```
52+
53+
54+
To fix this, the demo now uses the following `tsconfig.json` file:
55+
56+
```json
57+
{
58+
"compilerOptions": {
59+
"esModuleInterop": true,
60+
"module": "node16",
61+
"moduleResolution": "node16",
62+
"strict": true
63+
}
64+
}
65+
```

‎demo/ts-cjs-node16/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "csv-demo-ts-moduleresolution-node16-cjs",
2+
"name": "csv-demo-ts-cjs-node16",
33
"version": "0.2.10",
44
"dependencies": {
55
"csv-generate": "^4.2.7",
@@ -11,7 +11,7 @@
1111
"license": "MIT",
1212
"private": true,
1313
"devDependencies": {
14-
"typescript": "^5.1.6"
14+
"typescript": "^5.2.2"
1515
},
1616
"scripts": {
1717
"test": "tsc --noEmit"

‎demo/ts-cjs-node16/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"compilerOptions": {
33
"esModuleInterop": true,
4-
"module": "CommonJS",
5-
"moduleResolution": "node16",
4+
"module": "Node16",
5+
"moduleResolution": "Node16",
66
"strict": true
77
}
88
}

‎demo/ts-esm-node16/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
"stream-transform": "^3.2.7"
1313
},
1414
"devDependencies": {
15-
"@types/node": "^20.5.0",
15+
"@types/node": "^20.5.6",
1616
"coffeescript": "^2.7.0",
1717
"mocha": "^10.2.0",
1818
"should": "^13.2.3",
1919
"ts-node": "^10.9.1",
20-
"typescript": "^5.1.6"
20+
"typescript": "^5.2.2"
2121
},
2222
"mocha": {
2323
"inline-diffs": true,

‎demo/webpack-ts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"node-polyfill-webpack-plugin": "^2.0.1",
1919
"stream-browserify": "^3.0.0",
2020
"ts-loader": "^9.4.4",
21-
"typescript": "^5.1.6",
21+
"typescript": "^5.2.2",
2222
"webpack": "^5.88.2",
2323
"webpack-cli": "^5.1.4"
2424
},

‎packages/csv-generate/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212
"author": "David Worms <david@adaltas.com> (https://www.adaltas.com)",
1313
"devDependencies": {
1414
"@rollup/plugin-eslint": "^9.0.4",
15-
"@rollup/plugin-node-resolve": "^15.1.0",
15+
"@rollup/plugin-node-resolve": "^15.2.1",
1616
"@types/mocha": "^10.0.1",
17-
"@types/node": "^20.5.0",
17+
"@types/node": "^20.5.6",
1818
"@types/should": "^13.0.0",
1919
"coffeescript": "~2.7.0",
2020
"each": "^2.4.0",
2121
"eslint": "^8.47.0",
2222
"mocha": "~10.2.0",
23-
"rollup": "^3.28.0",
23+
"rollup": "^3.28.1",
2424
"rollup-plugin-node-builtins": "^2.1.2",
2525
"rollup-plugin-node-globals": "^1.4.0",
2626
"should": "~13.2.3",
2727
"ts-node": "^10.9.1",
28-
"typescript": "^5.1.6"
28+
"typescript": "^5.2.2"
2929
},
3030
"exports": {
3131
".": {

‎packages/csv-parse/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@
6161
},
6262
"devDependencies": {
6363
"@rollup/plugin-eslint": "^9.0.4",
64-
"@rollup/plugin-node-resolve": "^15.1.0",
64+
"@rollup/plugin-node-resolve": "^15.2.1",
6565
"@types/mocha": "^10.0.1",
66-
"@types/node": "^20.5.0",
66+
"@types/node": "^20.5.6",
6767
"coffeelint": "^2.1.0",
6868
"coffeescript": "^2.7.0",
6969
"csv-generate": "^4.2.7",
@@ -72,13 +72,13 @@
7272
"eslint": "^8.47.0",
7373
"mocha": "^10.2.0",
7474
"pad": "^3.2.0",
75-
"rollup": "^3.28.0",
75+
"rollup": "^3.28.1",
7676
"rollup-plugin-node-builtins": "^2.1.2",
7777
"rollup-plugin-node-globals": "^1.4.0",
7878
"should": "^13.2.3",
7979
"stream-transform": "^3.2.7",
8080
"ts-node": "^10.9.1",
81-
"typescript": "^5.1.6"
81+
"typescript": "^5.2.2"
8282
},
8383
"files": [
8484
"dist",

‎packages/csv-stringify/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
"author": "David Worms <david@adaltas.com> (https://www.adaltas.com)",
1111
"devDependencies": {
1212
"@rollup/plugin-eslint": "^9.0.4",
13-
"@rollup/plugin-node-resolve": "^15.1.0",
13+
"@rollup/plugin-node-resolve": "^15.2.1",
1414
"@types/mocha": "^10.0.1",
15-
"@types/node": "^20.5.0",
15+
"@types/node": "^20.5.6",
1616
"@types/should": "^13.0.0",
1717
"coffeescript": "~2.7.0",
1818
"csv-generate": "^4.2.7",
1919
"each": "^2.4.0",
2020
"eslint": "^8.47.0",
2121
"express": "^4.18.2",
2222
"mocha": "~10.2.0",
23-
"rollup": "^3.28.0",
23+
"rollup": "^3.28.1",
2424
"rollup-plugin-node-builtins": "^2.1.2",
2525
"rollup-plugin-node-globals": "^1.4.0",
2626
"should": "~13.2.3",
2727
"ts-node": "^10.9.1",
28-
"typescript": "^5.1.6"
28+
"typescript": "^5.2.2"
2929
},
3030
"exports": {
3131
".": {

‎packages/csv/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@
2828
},
2929
"devDependencies": {
3030
"@rollup/plugin-eslint": "^9.0.4",
31-
"@rollup/plugin-node-resolve": "^15.1.0",
31+
"@rollup/plugin-node-resolve": "^15.2.1",
3232
"@types/mocha": "^10.0.1",
33-
"@types/node": "^20.5.0",
33+
"@types/node": "^20.5.6",
3434
"@types/should": "^13.0.0",
3535
"coffeescript": "~2.7.0",
3636
"each": "^2.4.0",
3737
"eslint": "^8.47.0",
3838
"mocha": "~10.2.0",
39-
"rollup": "^3.28.0",
39+
"rollup": "^3.28.1",
4040
"rollup-plugin-node-builtins": "^2.1.2",
4141
"rollup-plugin-node-globals": "^1.4.0",
4242
"should": "~13.2.3",
4343
"ts-node": "^10.9.1",
44-
"typescript": "^5.1.6"
44+
"typescript": "^5.2.2"
4545
},
4646
"engines": {
4747
"node": ">= 0.1.90"

‎packages/stream-transform/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
"author": "David Worms <david@adaltas.com> (https://www.adaltas.com)",
1212
"devDependencies": {
1313
"@rollup/plugin-eslint": "^9.0.4",
14-
"@rollup/plugin-node-resolve": "^15.1.0",
14+
"@rollup/plugin-node-resolve": "^15.2.1",
1515
"@types/mocha": "^10.0.1",
16-
"@types/node": "^20.5.0",
16+
"@types/node": "^20.5.6",
1717
"coffeescript": "~2.7.0",
1818
"csv-generate": "^4.2.7",
1919
"each": "^2.4.0",
2020
"eslint": "^8.47.0",
2121
"mocha": "~10.2.0",
2222
"pad": "~3.2.0",
23-
"rollup": "^3.28.0",
23+
"rollup": "^3.28.1",
2424
"rollup-plugin-node-builtins": "^2.1.2",
2525
"rollup-plugin-node-globals": "^1.4.0",
2626
"should": "~13.2.3",
2727
"ts-node": "^10.9.1",
28-
"typescript": "^5.1.6"
28+
"typescript": "^5.2.2"
2929
},
3030
"exports": {
3131
".": {

0 commit comments

Comments
 (0)
Please sign in to comment.