Node.js 在typescript中导入哈希ID时出现异常
我正在尝试在Typescript中导入Node.js 在typescript中导入哈希ID时出现异常,node.js,typescript,tsconfig,hashids,Node.js,Typescript,Tsconfig,Hashids,我正在尝试在Typescript中导入hashids: 您可以从中克隆代码 =============index.ts========== 从“hashid”导入hashid; const encoder=新的Hashids(); 但我得到了下一个错误: =============控制台========= 导出{Hashids作为默认值}; ^^^^^^ SyntaxError:意外标记“导出” at模块编译(内部/modules/cjs/loader.js:895:18) at Object
hashids
:
您可以从中克隆代码
=============index.ts==========
从“hashid”导入hashid;
const encoder=新的Hashids();
但我得到了下一个错误:
=============控制台=========
导出{Hashids作为默认值};
^^^^^^
SyntaxError:意外标记“导出”
at模块编译(内部/modules/cjs/loader.js:895:18)
at Object.Module._extensions..js(internal/modules/cjs/loader.js:995:10)
在Module.load(内部/modules/cjs/loader.js:815:32)
at Function.Module._load(内部/modules/cjs/loader.js:727:14)
at Module.require(内部/modules/cjs/loader.js:852:19)
根据需要(internal/modules/cjs/helpers.js:74:18)
反对。(/var/www/persona service/src/Example.ts:1:1)
at模块编译(内部/modules/cjs/loader.js:959:30)
在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"
}
这里会发生什么 检查hashids包的git repo时发现与导入某些节点版本相关的问题: 这里提到的解决方法是使用require而不是import
const Hashids = require('hashids/cjs');
我希望这能让您回到正轨。检查git repo中的hashids包时发现了与导入某些节点版本相关的问题: 这里提到的解决方法是使用require而不是import
const Hashids = require('hashids/cjs');
我希望这能让你回到正轨。谷歌搜索没用谷歌搜索没用