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

Meteor URL package interferes with NPM URL module (Package is not defined) #4

Open reohjs opened 8 years ago

reohjs commented 8 years ago

In the bundle served to the client, this line in the webpack dev server client is run:

var url = require('url');

But the url module is being resolved to the Meteor URL package which is required by the HTTP package and giving a Package is not defined error for this line:

var Meteor = Package.meteor.Meteor;

I assume this is because whichever package exports the Package global hasn't run yet

This is reproducible by adding the HTTP package to the meteor app

reohjs commented 8 years ago

I'm thinking we'd have to make meteor packages resolve only to e.g. meteor/url or make sure they don't load before the webpack dev-server client does

luisherranz commented 8 years ago

I see. I guess that's because meteor packages folder is added as modulesDirectory here: https://github.com/luisherranz/meteor-imports-webpack-plugin/blob/master/index.js#L78-L81

Could you take a look to see if there's a way to modify the preference order of those modulesDirectories?

reohjs commented 8 years ago

Removing those lines seems to work fine; I suspect there's another way to solve it by setting an appropriate resolve.alias configuration

Now running into the error with underscore...

adam187 commented 7 years ago

I had same issue.

Removing packages folder from modulesDirectory solved issue. (https://github.com/luisherranz/meteor-imports-webpack-plugin/blob/master/index.js#L78-L81)

Also adding alias config.resolve.alias.url = 'url/url.js'; helped.

@luisherranz Is it really necessary to have packages as modulesDirectories ? I didn't notice any issues with my app without it.

luisherranz commented 7 years ago

@luisherranz Is it really necessary to have packages as modulesDirectories ? I didn't notice any issues with my app without it.

I added this to be able to use the loaders of the dependencies of this package.

I guess it's probably not needed if you are using npm@3 because all the dependencies get installed in the same node_modules folder and webpack should be able to find the loaders.

I'm talking by memory here, not 100% sure. If you think they should be removed, go ahead :)