我正在尝试hashids
在 Typescript 中导入:
你可以从这里克隆代码
========== index.ts ==========
import Hashids from "hashids";
const encoder = new Hashids();
但我得到下一个错误:
=========== 控制台 =========
export { Hashids as default };
^^^^^^
SyntaxError: Unexpected token 'export'
at Module._compile (internal/modules/cjs/loader.js:895:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/var/www/persona-service/src/Example.ts:1:1)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Module.m._compile (/var/www/persona-service/node_modules/ts-node/src/index.ts:814:23)
at Module._extensions..js (internal/modules/cjs/loader.js:995:10)
这是我的tsconfig.json
{
"compilerOptions": {
"incremental": true,
"moduleResolution": "node",
"module": "CommonJS",
"esModuleInterop": true,
"target": "es6",
"types": [
"node",
"express",
"hashids"
]
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
我也在使用nodemon
这个配置:
{
"watch" : ["src"],
"ext": "ts",
"exec": "ts-node ./src/index.ts"
}
这里会发生什么?