I have 2 projects. One of them is written in typescript and is named tsproject
. Other one is written in js and is named jsproject
.
I builded the tsproject
by using tspc -p tsconfig.json
. The tsconfig.json is like this:
// tsproject/tsconfig.json
{
...,
"compilerOptions": {
...,
"target": "ES2018"
"module": "commonjs",
"outDir": "lib",
...,
},
...
}
After the building, I copied everything in the tsproject/lib
folder to jsproject/src/libs/tsproject
. I can use as
// jsproject/src/index.js
import { TsProjectClass } from '~/libs/tsproject'; // This class is exported as `export class TsProjectClass { ... }`
I use webpack in jsproject to build and here is the webpack.config.js
file:
// jsproject/webpack.config.js
const path = require('path');
const webpack = require('webpack');
const dotenv = require('dotenv').config();
const config = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'app.js',
},
externals: {
...
},
module: {
rules: [
{
test: /.js?$/,
exclude: /node_modules/,
include: path.resolve(__dirname, 'src'),
use: {
loader: 'babel-loader',
},
},
],
},
plugins: [new webpack.EnvironmentPlugin(Object.keys(process.env))],
};
module.exports = config;
However, when I build using Webpack I get this error:
WARNING in ./src/index.js 38:19-39
export 'default' (imported as 'TsProjectclass') was not found in './libs/tsproject' (possible exports: __esModule)
What am I missing?
Thanks for replies.