Reputation: 1089
I am using typescript with the following build instructions.
"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"
One of my .ts
files imports mongoose. When running npm start
I get the following error. in the .d.ts
file
\lib\models\v1\collection1.model.d.ts:1
(function (exports, require, module, __filename, __dirname) { import mongoose from 'mongoose';
^^^^^^^^
SyntaxError: Unexpected identifier
note "@types/mongoose" and "mongoose" are dependence already.
the content of collection1.model.d.ts is as follows. which is generated by 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"
]
}
Upvotes: 0
Views: 1054
Reputation: 1089
So the problem is I should have not used babel and instead simply use tsc to generate all the code. Thank you to all that helped
Upvotes: 0