-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
using tsconfig.json with es2015/es6 module output #212
Comments
Maybe. ES6 modules might be supported in node.js natively one day so deviating from spec will cause issues. Happy to consider it though, but my feeling is no as the goals of this project is to have it act like |
Perhaps a way to override the setting without using environment variables, like a |
See #4. I haven't really done it because I haven't had the need and don't quite understand how it'd work for others yet. |
The way I do it, is setting the env in package.json/npm 'run scripts' section. The requires ugly double escaping, but it works as a (hopefully temporary) workaround. Example for other people who encounter is problem, a line in from my package.json, inside the scripts section:
But my question is, should ts-node even allow configuration that doesn't work. Is there any use-case where you would want ts-node outputting a module format that isn't supported by node (only commonjs and umd output work now)? The other option is just documenting this problem and the possible workarounds.... and wait for es6 support in node to make this problem go away. |
What if someone wants ES6 module output because they use it with Babel transpilation or something similar? I'd rather not enforce a specific configuration, as it's up to people and configuration for that. |
Thanks for this workaround, I finally ended up with
This works on Windows. No luck on OSX so far. |
Any news? @MrCrimp suggestion works but it isn't ideal, and it doesn't seem to work on other operating systems. I tried with cross-env but it also doesn't work due to a bug when sending JSON (kentcdodds/cross-env#30) |
@Apidcloud What news do you expect? I have no intention on changing the behaviour, I'd suggest using multiple |
Using multiple tsconfig can do the trick, but either way, my question was referring to whether you are planning on supporting ES6 modules or not. Also, @MrCrimp and @jorrit-wehelp, check this thread. It's not ideal, but it's possible to have it running on OSX, Linux and Windows with slightly different test scripts. |
I am not going to do anything to support ES6 modules. I'm not really sure what that would mean for |
I understand 👍 and exactly, I am using ES6 modules for the normal build process and transpiling them to ES5 using babel afterwards (I need both versions). For unit testing I'm changing it (with ts-node's environment variable) to commonjs. Thanks again! |
- Change `module` from `commonjs` to `es2015`. - Fix `ts-node` problem with `es2015` module. (`ts-node` hasn't supported `es2015` yet. More info TypeStrong/ts-node#212)
I just found this handy |
Just want to add on to what @collheesi mentioned. If you want to use ESmodules (AKA import syntax), to test quick scripts, overwrite the default
import { spawn } from 'child_process';
const child = spawn('pwd');
child.on('exit', (code: Number, signal:string):void => {
console.log(`child process exited with code ${code} and signal ${signal}`);
}); You may ask yourself what/where are those options I'm passing coming from? These key-values are options you pass to This is all on the |
There's experimental ESM support now, see here |
The The new |
I have a typescript project that is build and distributed as es6 modules, so I have a tsconfig which sets "module": "es6".
When using ts-node in this project it doesn't work, (ts-)node throws SyntaxErrors since it doesn't support es6 modules yet. (I work around this by setting the TS_NODE_COMPILER_OPTIONS env variable)
But i'm wondering if ts-node should not just always 'override' this settings from a tsconfig file and always use commonjs...
The text was updated successfully, but these errors were encountered: