jedwards1211 / meteor-imports-webpack-plugin

Webpack plugin to import and use Meteor packages like if they were real NPM packages.
MIT License
25 stars 10 forks source link

underscore.js error from Meteor #5

Open gitTerebi opened 8 years ago

gitTerebi commented 8 years ago

I get this "underscore.js:60 Uncaught TypeError: Cannot read property '_' of undefined"

Since meteor always bundles in underscore, webpack processes it and then this section of code breaks.

var previousUnderscore = root._;

I tried adding underscore to the exclude section in webpack config, but then it breaks with "require" not found error from the react hot reload module. :(

luisherranz commented 8 years ago

I am really glad that a lot of people is trying to use this plugin. Some of you had problems, others got it working.

I am sure a lot more can be done fixing bugs and making it work with edge cases, but this plugin won't be useful once Meteor 1.5 is released.

So I think you should wait until Meteor 1.5 and use the official npm Meteor version: https://forums.meteor.com/t/excited-to-know-that-work-on-meteor-1-5-has-been-started/24481

Quoting @benjamn:

Meteor 1.5 will be the first version of Meteor that is installable from npm

👍

reohjs commented 8 years ago

Unfortunately, for whatever reason, MDG decided Apollo integration was more important so npm migration isn't coming anytime soon...

I managed to get the Webpack imports-loader working for the Meteor packages so that they have this === window like this:

// Add a loader to inject this as window in the meteor packages.
compiler.options.module.loaders.push({
  meteorImports: true,
  test: /\.js$/,
  include: [meteorPackages],
  loader: 'imports?this=>window'
});

https://github.com/luisherranz/meteor-imports-webpack-plugin/blob/master/index.js#L65-L70

I checked before and after for the output bundle and they now have .call(window) as shown here BUT it's not modifying the underscore file...

gitTerebi commented 8 years ago

So using your changes are you able to get Meteor to run via webpack without underscore throwing an error?

The only other solution right now is to go back to DDP and roll my own "minimongo" read only collection.

reohjs commented 8 years ago

@gitTerebi No, because the underscore.js file is being ignored by the loader. No idea why..

You may want to take a look at Asteroid too: http://julian.io/react-with-webpack-meteor-as-a-backend/

gitTerebi commented 8 years ago

Yes I had a look as asteroid, but it actually has error. When you subscribe to the onAdd event, it fires even when a document is removed.

Worse still was trying to get the read only collections working (didn't work).

Thats why i'm having to go back to ddp and roll my own collection eg https://gist.github.com/wearhere/acf71ceba51a2e77c8ec