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

No default export #591

Closed
noelheesen opened this issue Oct 8, 2019 · 3 comments
Closed

No default export #591

noelheesen opened this issue Oct 8, 2019 · 3 comments

Comments

@noelheesen
Copy link

Hello,

After following the manual I'm stuck on importing luxon as it provides no default export. This issue has been resolved earlier but since the manual states you can use es6 syntax I think this issue should be readdressed.

Here is an example repo: https://github.com/noelheesen/luxon-example
either open the index.html or use tsc index.ts to rebuild (typescript already catches the error).

Note that the flag `esModuleInterop` tsconfig
doesn't help in creating a default export.

I think the manual needs to be adjusted to the import * as luxon statemen or even better, provide a default export.

Yours,

@icambron
Copy link
Member

icambron commented Oct 8, 2019

What adjustment to the manual are you proposing? It's not immediately obvious to me where it's implying you should use a default export...

@noelheesen
Copy link
Author

It seems partial import's aren't working either. It keeps saying exports is undefined. I've updated the demo repo to match the following part of the manual:

Webpack

npm install --save luxon

import { DateTime } from "luxon";

Error in console: ReferenceError: exports is not defined

@icambron
Copy link
Member

icambron commented Oct 8, 2019

You're emitting a commonjs module ("module": "commonjs") and then loading it directly in the browser. The browser doesn't support commonjs, so it fails with that error. Remember that tsc is a compiler, not a bundler.

You have three options:

  1. Use a module loader like Webpack to consume the module you're compiling. This is what most people do, hence the instructions.
  2. Set that module setting to "ESNext" and consume it with a browser-native module support (this has a ton of gotchas and I don't recommend it)
  3. Use the browser global build and ignore module concerns

See, e.g. here: https://stackoverflow.com/questions/54670544/how-to-fix-referenceerror-exports-is-not-defined-in-a-pure-typescript-project

I know what you're thinking: "man, modern JS toolchains are a huge pain! Why is it so complicated?" I agree, but I don't make the rules...

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