我试图将 typescript 库与 node 一起使用,但我不断收到这些 SyntaxErrors。我正在使用 ts-node-dev 从 package.json 运行开发脚本。错误显示在导入语句附近,我不确定我的 tsconfig.json 是否有问题(它也附在下面)。但我正在使用 "module":"commonjs" 。
[INFO] 13:22:15 ts-node-dev ver. 1.1.8 (using ts-node ver. 9.1.1, typescript ver. 4.4.3)
/mnt/d/Polkadex/web-proxy/node_modules/@polkadot/keyring/index.js:3
import "./detectPackage.js";
^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected string
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Module._compile (/mnt/d/Polkadex/web-proxy/node_modules/source-map-support/source-map-support.js:568:25)
at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Object.nodeDevHook [as .js] (/mnt/d/Polkadex/web-proxy/node_modules/ts-node-dev/lib/hook.js:63:13)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/mnt/d/Polkadex/web-proxy/src/helpers/testUser.ts:1:1)
[ERROR] 13:22:19 SyntaxError: Unexpected string
包.json
{
"name": "web-proxy",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"@polkadot/api": "^6.0.3",
"@polkadot/keyring": "^7.4.1",
"@polkadot/util": "^7.4.1",
"@polkadot/util-crypto": "^7.4.1",
"axios": "^0.21.4",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"typescript": "^4.4.3"
},
"devDependencies": {
"@polkadot/typegen": "^6.0.3",
"@types/axios": "^0.14.0",
"@types/express": "^4.17.13",
"ts-node": "^10.2.1",
"ts-node-dev": "^1.1.8"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"generate:defs": "ts-node --skip-project node_modules/.bin/polkadot-types-from-defs --package sample-polkadotjs-typegen/interfaces --input ./src/interfaces",
"dev": "ts-node-dev --respawn --pretty --transpile-only src/index.ts"
},
"author": "",
"license": "ISC"
}
tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
},
"exclude": [
"./node_modules"
],
"include": [
"./src/**/*"
]
}