aleclarson / vite-tsconfig-paths

Support for TypeScript's path mapping in Vite
MIT License
1.35k stars 50 forks source link

cjs export problem #75

Closed KevinBrother closed 2 weeks ago

KevinBrother commented 2 years ago

tsup generate cjs will wrap another key,such as 'src_default as default'.

So i bundle myself scripts will not work in cjs server mode.

Dose it work if you add server.js in cjs mode? Not esm mode server.mjs.

dirst/index.js now:

export {
  src_default as default
};

i think it should be: (direct exposure function)

module.exports = src_default
aleclarson commented 2 years ago

Actually, in the latest version of this plugin, the dist/index.js file uses this:

exports.default = src_default;

If I understand you correctly, you are bundling your server to CJS and the dist/index.js file is causing you problems?

Need a reproduction

KevinBrother commented 1 year ago

yes, you understand correctly.

image

it's work. But i think should't do it like this. Because the export of 'vite-tsconfig-paths' should consistently, like react etc,in cjs and mjs.

const tsconfigPaths = require('vite-tsconfig-paths');
import tsconfigPaths from tsconfigPaths';

I think all the 'tsconfigPaths' up here are functions.

// not this
const {default} = require('vite-tsconfig-paths');
aleclarson commented 2 weeks ago

This plugin no longer supports CJS, so I'm closing this.