Skip to content

Commit

Permalink
Fix typescript with cjs compile issue (#802)
Browse files Browse the repository at this point in the history
When I tried to run examples with some versions of typescript, some
versions(version< 5.3) failed to compile.
The main reason is line-bot-sdk-nodejs's compilerOption is wrong.
To provide dual package, we need to use `"module": "ESNext"` and
`"moduleResolution": "Bundler"`.
We used `NodeNext` but we should not because this repository will
support others not only Node.js.

Otherwise, TypeScript will explicitly write a resolution-mode to the
type definition files. (like `/// <reference types="node"
resolution-mode="require"/>`)
Although it should normally be written, there needs to be a way to turn
this off when supporting dual packages.


In addition, this change upgrades `target` from ES2018 to ES2022.
Node.js v18 supports ES2022.
ref: https:/microsoft/TypeScript/wiki/Node-Target-Mapping

Co-authored-by: Tokuhiro Matsuno <[email protected]>
  • Loading branch information
Yang-33 and tokuhirom authored Apr 5, 2024
1 parent ed3f213 commit 20dd1e1
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/getting-started/requirements.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Requirements

* **Node.js** >= 18.
* It uses ES2015.
* It uses ES2022.
* [**npm**](https://www.npmjs.com/), preferably >=10

Other dependencies are installed via npm, and do not need to be pre-installed.
2 changes: 1 addition & 1 deletion examples/echo-bot-ts-cjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/echo-bot-ts-cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"@types/express": "^4.17.17",
"@types/node": "^20.6.3",
"rimraf": "^5.0.1",
"typescript": "^5.4.3"
"typescript": "^5.2.2"
}
}
2 changes: 1 addition & 1 deletion examples/echo-bot-ts-cjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES2017",
"target": "ES2022",
"module": "commonjs",
"outDir": "./dist",
"strict": true,
Expand Down
4 changes: 2 additions & 2 deletions examples/echo-bot-ts-esm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ESNext",
"target": "ES2022",
"module": "NodeNext",
"outDir": "./dist",
"moduleResolution": "NodeNext",
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
},
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"target": "ES2022",
"esModuleInterop": true,
"target": "ES2018",
"noImplicitAny": true,
"newLine": "LF",
"sourceMap": true,
Expand Down

0 comments on commit 20dd1e1

Please sign in to comment.