-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Module parse failed #27
Comments
Hey @kmalakoff, Thanks a lot for letting us know, could you check that @mauriciosoares? |
Hey @zenorocha, I don't think I'll be able to focus so much in this project, If I have some free time I'll try to check it, but feel free to ask someone else to help you out with it. :) |
@kmalakoff what is your babel modules configuration? |
@kmalakoff I just had to change babel loader at //...
module: {
loaders: [
{
test: /\.js$/,
include: [
path.resolve(__dirname, "src"),
path.resolve(__dirname, "node_modules/clipboard/src")
],
loader: 'babel'
}
]
},
//... |
This is my configuration:
This is a general purpose webpack config so I would prefer not to add those include options specifically for this library. Any idea why those lines are necessary? Also, why does the browser needs to require the src directory instead of dist? I can include the compiled code in dist just fine although I do get a warning |
@zenorocha could this be solved by changing the browser field in |
Just ran into this. :) @kmalakoff The problem is clipboard modules use ES6, and you are excluding One normal solution is to provide a |
@kmalakoff as @daviferreira mentioned you just need to remove |
Hmmmm. I definitely do not want to compile node_modules since modules should be distributed in an immediately useable form and it will be a productivity hit to compile all of the others when they are not necessary. What I do on my compiled-to projects is use webpack to generate a compiled, dist version in universal module (UMD) form with all of the dependencies externally provided. For example, take a look at react-nvd3. Would that work for clipboard.js? eg. distribute in a UMD form with external symbols |
@vekat's has a valid point. The "browser" field in your When I change the "browser" field locally in node_modules/clipboard/package.json, the
Which is better than an error. |
@zenorocha regarding the |
Don't worry @kmalakoff. I'm just super busy right now but it's on my todo list |
Webpack allows you to easily alias the destination of clipboard to use an already compiled version of it. I have this in my webpack config: resolve: {
alias: {
clipboard: 'clipboard/dist/clipboard',
}
} You'll get the same warning that @natorojr mentions, but it removes the need to compile clipboard via the babel-loader. |
@craigjennings11 the library should be fixed so workarounds are unnecessary. See: #85 |
@kmalakoff If that's the standard, then you have a lot of libraries to update 😉 |
@craigjennings11 totally, but it is worth it. Standards for library authors really help the users of their libraries...imagine how many people run into the same problem and the amount of wasted effort there is finding workarounds. We've all got better things to do! |
I have the same feeling as @craigjennings11. This is a library written in ES6 and the way you transpile ES6 in Webpack is by using babel-loader. |
@zenorocha if you believe that changing the way webpack works is best way to resolve this, please file a feature request or bug report with webpack then and link to it here. Of course, if I look at my applications and clipboard is the only one that requires custom webpack configuration (as it is), I'd venture to guess that your feeling is probably not in the majority. Either way, as a library author, you should make sure the users of your library do not waste time on non-value added activities so please let's get this resolved. I've volunteered to submit a solution to standardize clipboard's client distribution through pre-compilied, UMD-packaged assets which could be a good way to handle this in the short term. |
I don't need to change webpack because it already offers what you need to import Clipboard.js. Here are two different ways of using Clipboard.js with Webpack:
|
@zenorocha sorry, but those are workarounds, not solutions. A properly distributed library should require zero custom webpack configuration. If you do not agree with this premise as a library author, then there is no reason for me to continue trying to help. 😉 |
The pull request to fix this has been closed: #85. Closing this issue. |
I do want to offer the best experience for everybody when requiring this library. But your proposed solution included a bunch of opinionated tooling and your own personal preferences. I'll leave this issue open for now, if anybody has an idea on how to improve it. |
No that's fine. Let's keep it closed since your main line of argument is that no changes are needed since all of your library users can make unnecessary changes to their webpack configuration files to support clipboard. I'm not in agreement with this as a principle of open source library distribution. As for the PR, I've explained my time availability for volunteer work and responded to your feedback in the PR. You can merge and update to your alternative beliefs easily enough, but have instead decided to be a bit confrontational |
https://blog.newrelic.com/2014/11/05/open-source-contribution/ |
@heldr no problem with having my PR closed or rewritten. Totally agreed that the library maintainer / author needs to ensure solutions are best for all users. That's not what this issue or the PR is really about... Like other users, I just want this problem solved. I do not agree with the premise that the library users should modify their configurations as @zenorocha was arguing and users shouldn't have to build the library using babel for the browser. Unnecessary configuration simply wastes people's time when it can actually be fixed / removed pretty easily (which is why I took the time to submit the PR in the first place...a little work on my side could help new users save time bumping into configuration or build problems). To respond quickly to this issue, the contributors on clipboard could quickly modify my PR to triage the issue (removing any irreversible library decisions like embedding references to embedded modules, etc and putting preference-based bike-shedding issues aside) and then buy the time to solve it with the tooling they prefer. At least this thread is creating the impetus for action! |
Your intentions were good, but your pull request not, period. The way you presented, this was a problem specific to Webpack users which wasn't really the case. It affected all module loaders because people were requiring a ES6 module from npm that wasn't transpiled. This problem is now fixed in |
I am using webpack and babel to package this library, but get the following error:
I see you have configured the browser version to point to a different file than in Node.js so I am manually pointing to clipboard/dist/clipboard.js to work around this.
If I copy clipboard.js and clipboard-action.js into my project, they seem to work so I think it has something to do with the way package.json is set up.
The text was updated successfully, but these errors were encountered: