Skip to content

Do not crash on namespace and side-effect imports - #2893

Merged
NullVoxPopuli merged 1 commit into
ember-cli:masterfrom
bardrop-oss:fix-crash-on-namespace-and-bare-imports
Nov 19, 2026
Merged

NullVoxPopuli merged 1 commit into
ember-cli:masterfrom
bardrop-oss:fix-crash-on-namespace-and-bare-imports

Conversation

@bardrop

@bardrop bardrop commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Five rules crash with TypeError: Cannot read properties of undefined on import forms they did not expect:

Rule Code that crashes
no-unused-services import * as macros from '@ember/object/computed';
no-old-shims import * as Application from 'ember-application';
use-ember-data-rfc-395-imports import * as DSModel from 'ember-data/model';
no-ember-testing-in-module-scope import 'ember';
use-ember-get-and-set import 'ember';

ESLint stops linting the whole file when a rule throws, so one of these lines breaks lint for that file.

Causes:

  • no-unused-services skipped only default specifiers and then read spec.imported.name. A namespace specifier has no imported. It now looks at named specifiers only.
  • no-old-shims and use-ember-data-rfc-395-imports share buildFix in lib/utils/new-module.js, which read specifier.imported.name too. A namespace import has no single new module to point to, so the fix now returns null. The import is still reported, just without an autofix.
  • getEmberImportAliasName returned specifiers[0].local.name. With import 'ember' there is no specifier. With import { run } from 'ember' it returned run, so no-ember-testing-in-module-scope then watched run.testing and missed a later Ember.testing. It now returns the default import name, or null.

Tests: one case per rule plus two util cases. 7 of them fail on master and pass with this change. Full suite: 9973 passed. eslint and prettier --check are clean on the changed files.

I found these by running every rule over all code samples in the test suite, plus namespace / side-effect imports of every module the rules know. These five were the only crashes on realistic code.

no-unused-services read spec.imported.name for an
`import * as x from '@ember/object/computed'`, no-old-shims and
use-ember-data-rfc-395-imports did the same while building the fix for
a namespace import, and no-ember-testing-in-module-scope and
use-ember-get-and-set read specifiers[0] of `import 'ember'`.

getEmberImportAliasName now returns the default import name (or null),
so `import { run } from 'ember'` no longer makes `run` the Ember alias.
A namespace import of an old module is still reported, without a fix.
@NullVoxPopuli
NullVoxPopuli merged commit 7b17a6c into ember-cli:master Nov 19, 2026
12 checks passed
@NullVoxPopuli

Copy link
Copy Markdown
Contributor

highly recommend against using namespace imports btw <3

and import 'ember' is deprecated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants