Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with target = CommonJS in tsconfig #345

Closed
wiput1999 opened this issue Nov 22, 2019 · 4 comments
Closed

Problem with target = CommonJS in tsconfig #345

wiput1999 opened this issue Nov 22, 2019 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@wiput1999
Copy link

wiput1999 commented Nov 22, 2019

Current Behavior

I'm about to use tsdx to build library for Node.js but it still need to add .default after require. So I'm tried to change to export = and tsconfig target to CommonJS then

Module resolves to 'CommonJS'. This is incompatible with rollup, please use 'module: "ES2015"' or 'module: "ESNext"'.

is it possible to solve this issue?

Who does this impact? Who is this for?

Who using export = and target as commonjs

@wiput1999 wiput1999 changed the title Using target in tsconfig as CommonJS Problem with target = CommonJS in tsconfig Nov 22, 2019
@swyxio
Copy link
Collaborator

swyxio commented Dec 4, 2019

not sure. if you can investigate and propose a fix, please be my guest

@swyxio swyxio added the help wanted Extra attention is needed label Dec 4, 2019
@wiput1999
Copy link
Author

In my opinion but not sure I think it’s problem from rollup. Maybe next week if I’ve time I’ll try looking about this

@hardfist
Copy link

hardfist commented Jan 5, 2020

I think the problem is that tsdx use 'named' exports rather than 'auto' exports(which is rollup's default behavior ), which I think auto is more appropriate for the ugly export default things,
the difference between auto mode and named mode is different when treating export default

export default 42;

auto mode generates

'use strict';

var main = 10;

module.exports = main;

named mode generates

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var main = 10;

exports.default = main;

and auto mode works perfectly with node && browser

const lib = require('lib') // ok
import lib from 'lib' // ok when set esmoduleInterop: true

@sw-yx @jaredpalmer

@SokratisVidros
Copy link

I also came across the same issue while building a Node library. Is there a suggested tsconfig.json setup that eliminates the need of .default in CommonJS imports?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants