I am importing a module with an esModule export like below.
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = SomeNpmModule;
I import the module in my typscript code.
import SomeNpmModule from 'some-npm-module'
This gets transpiled to the following when I run tsup
const SomeNpmModule = require('some-npm-module');
Now when I use SomeNpmModule
, it is no longer SomeNpmModule
, but { default: SomeNpmModule }
.
How can I prevent this from happening.
Ideally tsup should generate the following code when using a default import, but it doesn't.
const SomeNpmModule = require('some-npm-module').default;
tsup.config.ts
import { defineConfig } from 'tsup';
export default defineConfig({
bundle: true,
clean: true,
dts: true,
entry: ['src/**/*.ts?(x)'],
entryPoints: ['src/index.ts'],
format: ['cjs', 'esm'],
minify: false,
outDir: 'lib',
publicDir: './public',
skipNodeModulesBundle: true,
splitting: true,
target: 'es5',
});
tsconfig.json
{
"compilerOptions": {
"allowJs": false,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"checkJs": false,
"composite": true,
"downlevelIteration": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"incremental": true,
"jsx": "react",
"lib": ["ES2022", "DOM", "ESNext"],
"module": "CommonJS",
"moduleResolution": "Node",
"noEmitOnError": false,
"noImplicitAny": false,
"noImplicitReturns": false,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveConstEnums": true,
"preserveSymlinks": true,
"removeComments": true,
"resolveJsonModule": true,
"rootDir": ".",
"skipLibCheck": true,
"sourceMap": false,
"strictNullChecks": true,
"target": "ES2022",
"types": ["node"],
"useUnknownInCatchVariables": false
},
"exclude": ["_"],
"typeAcquisition": {
"enable": true
}
}
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too