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

readConfig should enforce "module":"commonjs" #293

Closed
brad-jones opened this issue Mar 23, 2017 · 11 comments
Closed

readConfig should enforce "module":"commonjs" #293

brad-jones opened this issue Mar 23, 2017 · 11 comments

Comments

@brad-jones
Copy link

Until node supports es6 modules fully, it makes no sense to have typescript transpile to anything other than commonjs.

My project uses a tsconfig.json file with:

{
    "compilerOptions": {
        ...
        "module": "es6",
        ...
    }
}

And thus ts-node fails with my typescript gulp file.

All I am suggesting is to add:

result.config.compilerOptions.module = 'commonjs';

Alternatively if #4 was developed, it could possibly solve this issue as well.

@blakeembrey
Copy link
Member

blakeembrey commented Mar 23, 2017

No thanks. The module behaves how it should. If you need to override it, create a new tsconfig.json file and use that. It's conceivable that people are actually using ES6 modules (e.g. transpilation) and when real ES6 modules get released, it'll need to work. You're suggestion means two fast breaking changes for something that shouldn't be a feature anyway (just set the tsconfig.json file to what you want so it acts like tsc).

@brad-jones
Copy link
Author

Some explanation would be nice...

Do you have a suggested work around for the problem?

@blakeembrey
Copy link
Member

What didn't you like about the explanation? It's in the comment above.

@brad-jones
Copy link
Author

Huh? All you said was "No thanks".

@blakeembrey
Copy link
Member

Please just scroll up.

@brad-jones
Copy link
Author

Ok now github has loaded your edited comment.

@blakeembrey
Copy link
Member

No worries, I didn't add it initially when I hit enter but I edited it back in before you commented. Sorry for the confusion. I was trying to find a similar issue to this one from the past for reference, but couldn't find it. I'll try again now.

@blakeembrey
Copy link
Member

See #212.

@blakeembrey
Copy link
Member

By the way, are you using the CLI or with Gulp/mocha/etc? If you're using the CLI, it's very easy to use the -P option and TypeScript's new extends with tsconfig.json. It mostly resolved #4 for me to.

@brad-jones
Copy link
Author

Using gulp. I noticed definitions were released for Gulp v4 recently so thought I would have a crack at a typescript build pipeline.

Right now I have done this:

gulpfile.js

// Gulp tasks are written in typescript.
// We use https://github.com/TypeStrong/ts-node to transpile on the fly.
require('ts-node').register
({
    // Typechecking will be done by your IDE anyway,
    // so lets not bother doing it at runtime.
    fast: true,
    
    // Node does not yet understand ES6 modules
    compilerOptions:
    {
        module: "commonjs"
    }
});

// Load all tasks from the tasks directory.
require('require-dir')('./tasks', { recurse: true });

@blakeembrey
Copy link
Member

Cool, that looks like it should work. FWIW, Gulp does load gulpfile.ts for you automatically. The issue there, however, is what #4 attempts to solve since there's no easy way to inject custom compiler options in that situation. The best thing to do there might be to use tsconfig.json with extends on your ES6 config file - not sure if you need the ES6 specific module in the editor and other automatic discovery situations?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants