我正在使用带有以下构建说明的打字稿。
"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
文件导入了猫鼬。运行时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"
]
}