[英]unexpected identifier in .d.ts file
我正在使用带有以下构建说明的typescript。
"build:types": "tsc --emitDeclarationOnly",
"build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline",
"start": "npm run build:types && npm run build:js && node ./lib/bin/www.js"
我的一个.ts
文件导入了mongoose。 运行npm start
出现以下错误。 在.d.ts
文件中
\lib\models\v1\collection1.model.d.ts:1
(function (exports, require, module, __filename, __dirname) { import mongoose from 'mongoose';
^^^^^^^^
SyntaxError: Unexpected identifier
注意“@ types / mongoose”和“mongoose”已经是依赖。
collection1.model.d.ts的内容如下。 这是由tsc --emitDeclarationOnly
生成的
import mongoose from 'mongoose';
declare const _default: mongoose.Model<mongoose.Document, {}>;
export default _default;
tsconfig.json
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"declaration": true,
"outDir": "./lib",
"strict": false,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
},
"include": ["src"]
}
.babelrc
{
"presets": [
"@babel/env",
"@babel/typescript"
],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread",
"@babel/transform-runtime"
]
}
所以问题是我应该没有使用babel而是简单地使用tsc来生成所有代码。 谢谢所有有帮助的人
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.