Skip to content
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

Invalid imports from virtual modules halt the build with an unhelpful error #59

Closed
nightire opened this issue Dec 10, 2016 · 6 comments
Closed
Labels

Comments

@nightire
Copy link

In one of our addon's index.js:

module.exports = {
  options: {
    cssModules: {
      // ...
      virtualModules: {
        'ui-colors': {
          'ui-white': '#fff',
          // ...
        }
      }
    }
  }
}

and in one of .css file:

@value ui-white from 'ui-colors';

This works on ember-css-modules v0.5.x, but after I upgrade to v0.6.2, resolve this import from virtualModules will throw an error:

The Broccoli Plugin: [CSSModules] failed with:
TypeError: Cannot read property 'root' of undefined
    at resolveExternalPath (/Users/nightire/Code/ui.cform.io/node_modules/ember-css-modules/lib/resolve-path.js:45:38)
    at ModulesPreprocessor.resolvePath [as _resolvePath] (/Users/nightire/Code/ui.cform.io/node_modules/ember-css-modules/lib/resolve-path.js:15:12)
    at ModulesPreprocessor.resolvePath (/Users/nightire/Code/ui.cform.io/node_modules/ember-css-modules/lib/modules-preprocessor.js:165:15)
    at ModulesPreprocessor.onImportResolutionFailure (/Users/nightire/Code/ui.cform.io/node_modules/ember-css-modules/lib/modules-preprocessor.js:128:27)
    at /Users/nightire/Code/ui.cform.io/node_modules/broccoli-css-modules/lib/link-modules.js:47:19
    at Rule.each (/Users/nightire/Code/ui.cform.io/node_modules/postcss/lib/container.js:114:22)
    at /Users/nightire/Code/ui.cform.io/node_modules/broccoli-css-modules/lib/link-modules.js:42:10
    at tryCatch (/Users/nightire/Code/ui.cform.io/node_modules/rsvp/dist/rsvp.js:538:12)
    at invokeCallback (/Users/nightire/Code/ui.cform.io/node_modules/rsvp/dist/rsvp.js:553:13)
    at /Users/nightire/Code/ui.cform.io/node_modules/rsvp/dist/rsvp.js:628:16
    at flush (/Users/nightire/Code/ui.cform.io/node_modules/rsvp/dist/rsvp.js:2373:5)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

The broccoli plugin was instantiated at:
    at CSSModules.Plugin (/Users/nightire/Code/ui.cform.io/node_modules/broccoli-caching-writer/node_modules/broccoli-plugin/index.js:10:31)
    at CSSModules.CachingWriter [as constructor] (/Users/nightire/Code/ui.cform.io/node_modules/broccoli-caching-writer/index.js:18:10)
    at new CSSModules (/Users/nightire/Code/ui.cform.io/node_modules/broccoli-css-modules/index.js:26:10)
    at CSSModules (/Users/nightire/Code/ui.cform.io/node_modules/broccoli-css-modules/index.js:24:47)
    at ModulesPreprocessor.toTree (/Users/nightire/Code/ui.cform.io/node_modules/ember-css-modules/lib/modules-preprocessor.js:38:53)
    at /Users/nightire/Code/ui.cform.io/node_modules/ember-cli-preprocess-registry/preprocessors.js:180:26
    at Array.forEach (native)
    at processPlugins (/Users/nightire/Code/ui.cform.io/node_modules/ember-cli-preprocess-registry/preprocessors.js:178:11)
    at Function.module.exports.preprocessJs (/Users/nightire/Code/ui.cform.io/node_modules/ember-cli-preprocess-registry/preprocessors.js:171:10)
    at Class.preprocessJs (/Users/nightire/Code/ui.cform.io/node_modules/ember-cli/lib/models/addon.js:814:25)
    at Class.processedAddonJsFiles (/Users/nightire/Code/ui.cform.io/node_modules/ember-cli/lib/models/addon.js:826:17)
    at Class.compileAddon (/Users/nightire/Code/ui.cform.io/node_modules/ember-cli/lib/models/addon.js:742:24)
    at Class.treeForAddon (/Users/nightire/Code/ui.cform.io/node_modules/ember-cli/lib/models/addon.js:514:26)
    at Class._treeFor (/Users/nightire/Code/ui.cform.io/node_modules/ember-cli/lib/models/addon.js:371:33)
    at Class.treeFor (/Users/nightire/Code/ui.cform.io/node_modules/ember-cli/lib/models/addon.js:339:21)
    at /Users/nightire/Code/ui.cform.io/node_modules/ember-cli/lib/broccoli/ember-app.js:499:20

I was tracking this deeper and found in error has been thrown at https://github.com/salsify/ember-css-modules/blob/master/lib/resolve-path.js#L41 because addonName could not be parsed correctly:

2016-12-11 4 51 23

@dfreeman
Copy link
Member

Interesting. For virtual modules, resolvePath should never be called because the lookup should short-circuit on this line in broccoli-css-modules.

The test suite includes coverage for addons with virtual imports*, so at least in the general case they should be working. Would you be able to share a sample repo that reproduces the issue?

*See these files for the test:

@nightire
Copy link
Author

@dfreeman OK, let me try to talk to my boss first 😹

@nightire
Copy link
Author

@dfreeman Here it is: https://github.com/choice-form/ember-choice-ui

0.5.x in master branch which works well
0.6.4 in ember-css-modules branch which throws error

thanks for your time

@dfreeman
Copy link
Member

dfreeman commented Dec 13, 2016

@nightire Thanks for the reproduction! That led me right to the issue.

It looks like you have a typo (ui-gary instead of ui-gray) in ui-switch/styles.css. In 0.6.0, we started emitting a warning when you try to import values that don't exist, and that warning code breaks for virtual modules.

In the short term just fixing the typo should let you work around the issue, and I'll try to get a fix out in ember-css-modules in the next couple days so no one else hits this problem. Sorry that you ran into this!

@dfreeman dfreeman changed the title Can not resolve virtualModules in ember addon w/ ember-css-modules 0.6.2 Invalid imports from virtual modules halt the build with an unhelpful error Dec 13, 2016
@nightire
Copy link
Author

@dfreeman nice catch, how can I event miss that 🤔, thank you!

@dfreeman
Copy link
Member

@nightire I'm going to keep this open for now to track fixing the underlying issue, if that's ok with you :)

@dfreeman dfreeman reopened this Dec 13, 2016
rondale-sc added a commit to rondale-sc/ember-css-modules that referenced this issue May 11, 2017
* master:
  Update ember-test-helpers to get rid of the _lookupFactory deprecation
  Skip --skip-cleanup in tests
  Released v0.6.5
  Update CHANGELOG.
  Upgrade dependencies
  Support Ember CLI 2.12
  Remove readOnly modifier from `styles` properties
  Bump dependencies
  Yarn
  Fix salsify#59.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants