Scoped NPM breaks rendering test

When I switch the package.json to use a scoped NPM package name it breaks all my qunit rendering tests with the following error:

Failed to create an instance of 'component:json-editor'

If I edit index.js and change name to use the non-scoped NPM package name then the tests pass but I get a warning from ember-cli that the package.json name and the index.js name should match.

What’s the right way to fix this?

can you share code? what do you mean by scoped vs non-scoped npm package with respect to rendering?

pass but I get a warning from ember-cli that the package.json name and the index.js name should match.

This is correct. they must match.

This is used on an internal work project so I don’t have an easy way to share the code. But basically if I change name in package.json from ember-json-editor to @vzmi/ember-json-editor then all my rendering tests fail with

global failure: Error: Assertion Failed: Failed to create an instance of 'component:json-editor'. Most likely an improperly defined class or an invalid module export.

My application test fails with:

global failure: Error: Could not find module `ember-json-editor/components/json-editor` imported from `dummy/components/json-editor`

this error gives the hint:

global failure: Error: 
  Could not find module `ember-json-editor/components/json-editor` 
  imported from `dummy/components/json-editor`

so you have a component, json-editor, that is trying this import:

import ... from 'ember-json-editor/components/json-editor';

but since the package is renamed, the import path also needs to be renamed:

import ... from '@vzmi/ember-json-editor/components/json-editor';

and the name entry in index.js of the root of the addon also needs to be renamed to include the scope as well.

Thank you, that is the fix. Sometimes the answers are obvious. :slight_smile: Using it in the same repo I thought I was importing a file path rather than a package name without thinking about it.

1 Like