es6 import. UnhandledPromiseRejectionWarning
igisav opened this issue · 3 comments
as described in this issue, I import lib as follows:
import bodyParser from "body-parser";
import bodyParserXml from "body-parser-xml";
However, then I get
(node:98360) UnhandledPromiseRejectionWarning: TypeError: body_parser_xml_1.default is not a function
Usage with require
works well, but is not wanted by Eslint.
Do you have suggestion how to fix this?
body_parser_xml_1.default
This looks like you are using webpack or some other transpiler to bundle the codebase. Could you provide some more information on your project setup? Are you using TypeScript? Is it being bundled with webpack?
its a nodejs app with this webpack config:
module.exports = {
entry: ['webpack/hot/poll?1000', './src/main.hmr.ts'],
watch: true,
target: 'node',
externals: [
nodeExternals({
whitelist: ['webpack/hot/poll?1000'],
}),
],
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
mode: "development",
resolve: {
extensions: ['.tsx', '.ts', '.js','.env'],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'server.js',
},
};
and tsconfig:
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./src",
"moduleResolution": "node",
"esModuleInterop": true
}
I think there is some compatibility issue here between webpack, ts-loader and TypeScript. This isn't specific to this project, it's a more general configuration issue.
I suggest you try Stack Overflow to see if you can figure out the changes you need to make to your webpack and/or TypeScript configuration to make this work.