Is there a way to use addons in engine by listing them in engine's package.json without listing in host app's package.json

I listed a addon in ember engine’s package.json under dependency and it isn’t included in neither host app nor engine’s vendor. I get error as “component or helper named “dialog-modal” could not be found”.

Should addon be listed in host app’s package.json to be used in engine?

Is this engine an in-repo addon? If so I think you CAN have separate dependencies in an in-repo addon’s package but they must be installed separately too (see In-repo addon dependencies · Issue #4164 · ember-cli/ember-cli · GitHub)

yes am using a in-repo engine and i need a adddon only inside the engine.So say i need 5 addons which are to be used only in engine, if i list them in host app’s package.json … the code will reside in app’s vendor.js . This isnt the correct approach right @dknutsen

I need the addons code to reside in engine’s vendor.js file

I mean that’s not necessarily “wrong” in that it’s how in-repo addons are kinda meant to work. But it sounds like if you don’t like that approach then you can do npm/yarn installs in the in-repo addon to install the addon’s dependencies. Alternatively you could make it a separate-repo addon which would make it behave as you’d expect.

So if i keep it as separate addon or engine , where will the code of the addon’s listed in engine’s package.json reside ? In host app’s vendor or separate engine’s vendor @dknutsen

I think in the engine’s, but I think the answer is also a little nuanced. From the ember-engines guides (section on deduplication):

ember-engines will automatically try to deduplicate addons used by your host app and (lazy loaded) engine(s). This means that addons that both the host app and an engine rely on, are only included in the vendor bundle of the host app. This ensures that you do not ship the addon code multiple times to your users. If addons are not included in the host app, they will be included in the engine’s vendor bundle.

If i run npm install in in-repo engine directory, the addon already listed in host-app’s pacakge.json gets duplicated in engine’s vendor. Why is that duplication occurring? @dknutsen

what do both package.json files look like?

when i give npm install in engine directory, the addons that are listed in both host app and engine’ package.json get inserted in both engine’s and host-app’s vendor file. This leads to duplication of code. The version of addon listed in both host app and engine is same. Why is this?

example:

host-app package.json devDependencies { addon-a : "^1.1" }

engine-a package.json dependencies{ addon-a : "^1.1", addon-b: "^2.1" }

when i run npm install on host-app package.json , the addon-a gets into host-app’ vendor. Now when i run npm install in engine-a directory , addon-a gets installed again and code is inserted in engine-a vendor.js though they are of same version.

Expected behaviour: I only want addon-b which is used by engine alone to be inserted in engine’s vendor and addon-a used by both host app and engine must be in host app vendor. @dknutsen

I don’t know what to tell you if you can’t share the code or, preferably, a minimal reproduction. And you’ve already opened a github issue… Either you’ve discovered a bug, in which case a minimal reproduction repo would be hugely helpful to the maintainers, or you have something wrong with your code, in which case someone would need to look at your actual code or a minimal reproduction repo to help debug. There’s not much else I can suggest as-is.

1 Like