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

docs: correct use of individual package in node env #682

Merged
merged 1 commit into from Nov 8, 2018

Conversation

hemal7735
Copy link
Member

What kind of change does this PR introduce?
README docs

Did you add tests for your changes? NA

If relevant, did you update the documentation? NA

Summary
I found out while playing around with the examples given in the doc.
We transpile the ts files using babel which converts

export default [func/variables]
to

Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1

Does this PR introduce a breaking change? No

@jsf-clabot
Copy link

jsf-clabot commented Nov 5, 2018

CLA assistant check
All committers have signed the CLA.

@hemal7735
Copy link
Member Author

@dhruvdutt can you review please?

Copy link
Member

@evenstensberg evenstensberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, could you sign the CLA?

@hemal7735
Copy link
Member Author

@evenstensberg Yes, I did after I got the notice from jsf-clabot

@webpack-bot
Copy link

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

@ematipico
Copy link
Contributor

ematipico commented Nov 5, 2018

Although this is a bug!
In a nodejs environment we don't have the concept of .default because we just use CommonJS file resolution!

We should keep documentation like it is and fix the TypeScript compilation

@hemal7735
Copy link
Member Author

How will we fix the TypeScript compilation for that? Isn't this the work of babel?
In CommonJS we don't have the concept of .default, however we do have the concept of exporting more than one things, and in this case, it is a simple default.
In package - serve, we export many things, in that case, we will need to use this, or serve will need the same structure as rest of the packages.

@dhruvdutt
Copy link
Member

@ematipico
Copy link
Contributor

ematipico commented Nov 5, 2018

basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html

That's an opinion and everything is relative. That's not the issue here.

@hemal7735 No, we use TypeScript for compiling the code. What I would expect from the compilation is something like this:

Before

export default something() {}

After

module.exports = something() {}

Instead, TypeScript does something dumb and consider default as the name of the function when instead it's a particular syntax.
Probably there's a configuration for that.

@hemal7735
Copy link
Member Author

@hemal7735 No, we use TypeScript for compiling the code. What I would expect from the compilation is something like this:

Before

export default something() {}

After

module.exports = something() {}

Instead, TypeScript does something dumb and consider default as the name of the function when instead it's a particular syntax.
Probably there's a configuration for that.

It will still do if we have both default and named exports. But yeah, I got your point that it should do

module.exports = something() {}

if default is the only export. Maybe it's a feature request for both babel and tsc 😅

@ematipico ematipico merged commit 58756f7 into webpack:master Nov 8, 2018
@hemal7735 hemal7735 deleted the fix/readme-usage-node branch November 8, 2018 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants