-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
knockout debug and release both being pulled in #424
Comments
knockout passes the http://webpack.github.io/docs/shimming-modules.html#broken-commonjs
This also means the |
Where does that happen? Is it here? This should be resolved with a pull-request @kmalakoff, so other webpack/browserify users won't run into the same situation. |
Yep. https://github.com/knockout/knockout/blob/master/build/fragments/amd-pre.js#L6 I think this is even wrong. The @mbest has added it in knockout/knockout@847e1f1 |
@kmalakoff Could you do a pull-request? |
Thank you for looking into this. @sokra: if I understand correctly, you are saying that the static analysis warning is actually the cause of the library being included twice (eg. the issues are linked)? or is it just another unrelated issue? @jhnns I think you are asking me to create a pull-request on Knockout with a patch for the way they are implementing their module system support? I'm really not an expert in this area (for example, I've never used AMD on a project) which is why I'm using webpack...leave it to experts like yourselves! Of course, I understand that you guys also only have limited time and cannot get into issues on every incompatible library. I could study one of my webpack builds, try to copy the pattern into knockout, and submit a pull request. If I understand correctly, there is a problem with this and this. If I create a patch, would one of you be willing to review it before I submit it as a pull-request? @sokra: unfortunately, the workaround does not work well for libraries (like Knockback) to use webpack-style requires like As an aside, we are considering webpack to replace Brunch as our client application build system (I ran into this knockout problem during my evaluations). We are still trying to find a workaround for compile-time resolution of require statements for our views. I've opened an issue on it. |
see http://webpack.github.io/docs/using-loaders.html#usage Instead of using the inline syntax { test: /knockout.build.output.knockout-latest\.js/, loader: "imports?require=>false" } require("knockout"); |
Sure, go ahead 😄 |
I'm not so familiar with the difference between the two. Is it that the former accepts a callback function and the latter doesn't? If that's the case, does that mean that those using Knockout as a CommonJS module won't be able to use the "require" feature for modules? |
Knockout currently prefers the CommonJS module system over AMD. If that preference were switched, would that help? It seems that the workaround proposed above would make webpack include Knockout as an AMD module. |
CommonJs: So yes Knockout as CommonJS module won't be able to use the "require" feature. But as webpack relies on static analysis it won't be able to use the "require" feature at all... (even with AMD). In general it's a bad idea to pass around require strings or the |
http://knockoutjs.com/documentation/component-registration.html The documentation tells that you need use an AMD module with the |
Thanks for the details. I found that there's already a documentation section about using CommonJs-style |
@mbest would you be open to changing the module loading patterns and not having require being passed in for Knockout? Is there an example of 'possiblyGetConfigFromAmd'? It seems like the only place where the require is used inside Knockout and maybe there is a different way to do it? Maybe the caller should be responsible for the async loading of config and just pass it to Knockout? (I'm just guessing here because I'm not sure what it is for) |
I've been playing around more with this. When I use a bower install of knockout (from my own repo at https://github.com/kmalakoff/knockout) with the require statement, here's the output:
But if I comment out the require statement (https://github.com/kmalakoff/knockout/tree/no_amd), everything just works. |
It looks like the problem is caused by The error is because webpack includes everything in this folder (because the module's dependencies couldn't be analyzed statically) - and tries to load a json-file which requires the json-loader. |
Yeah, that's what the https://github.com/kmalakoff/knockout/tree/no_amd branch does - no errors in that case, but I'm not comfortable in removing core Knockout functionality. I'm opening an issue on knockout that will argue that their API should change that I know what their component framework does. I wonder why it is trying to load a json file. Is that something that can be disabled through webpack config so it succeeds? |
You could try the But it's good to fix these things in the popular libraries we use. People should stop messing around with the |
Sorry guys, but how is this solved in the end ? |
I ended up with a config file like:
|
I got a same problem and avoided by using kmalakoff's config #424 (comment) |
I am trying for a month to go from Brunch to WebPack in my current project and I am out of ideas on how to make it work. There is a forum/place/mailing list, something that can describe how to do, for the beginning, the same thing in WebPack as in Brunch? My stack is Backbone/Marionette. |
@devel-pa unforuntately, webpack is not as simple to configure as Brunch because it does more like static analysis and it depends on the actual JavaScript libraries you use (and how well they support module systems). I would image that maybe a Wiki page for library-by-library webpack settings recommendations would meet your needs since it depends on what you are using. |
Yep. But I think it's always the best to convince module author to provide CommonJS-compliant modules |
This looks similar: localForage/localForage#344. |
#424 (comment) is not working for us when running |
@kmalakoff Any luck with the current version? |
@bebraw sorry, I haven't tried the latest version yet. |
@kmalakoff Want to have another look? I think I'll close this. If you can repro the issue, please reopen. |
When I run webpack, it looks like both versions of knockout are being pulled in:
I'm not sure it this is an issue with webpack or knockout or some combination of them?
I have created a sample project here: https://github.com/kmalakoff/webpack_knockout_sample. Just run:
Thank you!
Kevin
The text was updated successfully, but these errors were encountered: