Question: How do I use this add-on to import a node package for use in a test?
There is a 3rd party node package which I would like to use in a component test. I created my import description in ember-cli-build.js:
nodeAssets: {
events: {
srcDir: 'events',
vendor: {
include: ['events.js']
}
}
}
I then import the file:
app.import('vendor/events/events.js');
And run the test:
ember test --serve
But when I do I get the error:
Could not find module ember-resolver`
Which obviously means that none of my tests can run. Can you help me by letting my know what I've done wrong?
It looks like that module is using CommonJS, which means it won't run in a browser out of the box. You'll probably want to look at using something like broccoli-rollup in the processTree() hook, or just using ember-browserify instead of this addon.
Thanks for the prompt response. I tried ember-browserify but it didn't seem to work; after following the steps in their docs, it still wasn't able to find the module.
I am very new at this but trying to learn quickly so I was wondering you had any good links (in addition to the one you provided above) which give a good description of how the whole build process works in Ember, why some packages work and some don't and how I can control/manipulate what is and isn't available in a built app? Also, perhaps when I should/could use a vendor-shim, browserify or your add-on?
There doesn't seem to be a whole lot of information immediately available (as mentioned at the top of your add-on's readme :-) )so any help or direction you can give would be greatly appreciated.
just in case anyone runs into this, note that ember-browserify also doesn't support being included in tests. The workaround for them that was discussed is to export the imported node module in a helper and then ignoring that helper in the non-test environment through ember-cli-build
https://github.com/ef4/ember-browserify/issues/14
broccoli-rollup was mentioned, but consider using ember-rollup
- still doing research. I haven't figured out my ideal way to import CommonJS modules into our ember v 2.13 project.
@BitBrit when you were trying to import the npm package using ember-browserify, did you make sure it was in devDependencies and was imported with the following syntax?
import X from `npm:events`
it may have been a syntax error that caused you to not find the module then