meteor / meteor-feature-requests

A tracker for Meteor issues that are requests for new functionality, not bugs.
Other
89 stars 3 forks source link

Prevent Build Warning For Known Missing Optional Modules #228

Open wavto opened 6 years ago

wavto commented 6 years ago

This feature request is a follow up of the bug report https://github.com/meteor/meteor/issues/9285.

Problem Description

I added the npm package bootstrap-slider to our Meteor project, which has an optional dependency to jQuery. That means the package calls require("jquery") in an if statement, at some point.

Since we do not use jQuery in our project, I got the following warning every time the Meteor server restarts:

Unable to resolve some modules:

  "jquery" in /my/project/path/node_modules/bootstrap-slider/dist/bootstrap-slider.js (web.browser)

If you notice problems related to these missing modules, consider running:

  meteor npm install --save jquery

As @benjamn described here the Meteor ImportScanner statically searches for require(<string literal>) in the code base, without evaluating if that code is ever executed.

This issue affects all packages requiring optional dependencies. For example, that means all packages build on top of this jQuery plugin "boilerplate", like bootstrap-slider in my actual case.

Change Proposal

I would add an option somewhere to be able to list "known missing modules". These modules should then be ignored by the ImportScanner or at least they should be considered before printing the warning. This way the annoying warning printed after every restart of the Meteor server will disappear.

The "known missing modules" option may be integrated into the package.json file or added to the run and build commands as an argument like meteor run --ignored-modules="foo, bar".

limikael commented 5 years ago

Any updates on this? Or anyone who knows a workaround?

wavto commented 5 years ago

We added the following to our package.json


  "scripts": {
    "//": "Workaround to prevent an annoying, wrongly printed meteor warning",
    "postinstall": "meteor node -e \"fs.existsSync('./node_modules/jquery') || fs.mkdirSync('./node_modules/jquery');\"",
limikael commented 5 years ago

@wavto: Clever! That works!