#@ember/application module empty under Embroider/Webpack?

1 messages · Page 1 of 1 (latest)

tepid acorn
#

The build of an app I'm migrating to Embroider seems to be correct. However, when I load the app in the browser, it shows me this error:

(0 , ember_application__WEBPACK_IMPORTED_MODULE_2_.getOwner) is not a function

I looked at what that module is and found this:

var _ember_application__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @ember/application */ ...);

The module seems to be completely empty:

Object.keys(ember_application__WEBPACK_IMPORTED_MODULE_2_).length => 0

Whereas other modules defined in the same file seems to have the exports, as expected:

Object.keys(ember_debug__WEBPACK_IMPORTED_MODULE_0_).length => 19

The error is thrown from ember-data's adapterFor function but I assume it'd be thrown anywhere getOwner is used.

I tried removing node_modules, clearing Embroider's cache and re-installing the whole project but it didn't change anything. I also tried finding an issue about this in the Embroider repo but I came up empty handed.

Do you have an idea what can go wrong? Thank you!

#

@ember/application module empty under Embroider/Webpack?

tight knoll
#

What's your ember-source version?

#

Get owner doesn't come from there anymore

#

Which package manager are you using?

tepid acorn
#

Sorry, I indeed missed those details:

ember-source: 5.1.1
yarn: 1.22.21
ember-data: 4.11.3

tight knoll
#

ah, your deps are probably messed up then

#

can you switch off yarn?

#

getOwner compatibility before and after 4.11 requires dependencies to be resolved correctly

#

and yarn@v1 doesn't actually allow for peer dependencies to resolve correctly

tepid acorn
#

Oh, I see, thank you. What do you mean by switching off of yarn? To switch to (p)npm?

tight knoll
#

yeah, or maybe yarn 4

#

yarn1 just isn't supported by anyone

#

even the yarn team

#

haha

tepid acorn
#

Gotcha. I guess the fact that Embroider (more precisely, Webpack) is more spec-compliant (stricter with how it resolves modules), more issues, which previously did not throw errors due to the laxness of the Ember-specific resolution mechanism, are now likely to surface

tight knoll
#

ah!

#

well that just won't work with ember-source v5+

#

well... now I'm puzzled

#

I need to check built output

#

can't trust source

#

reason being is that in v5 getOwner and setOwner come from @ember/owner

#

this could be a bug report for ember-data in the making!

#

oh weird, on npm, the latest version of @ember-data/store don't have getOwner? wat

tepid acorn
#

It does, in the latest version of ember-data, adapterFor is defined here:

tight knoll
#

ah, I was looking in store

#

hmmm...

#

yeah something is super fishy here

#

the code in ember-data tells me that it is wrong

#

oh actually

#

this isn't a problem

#

still hasn't been removed

#

might be scheduled for v6 then, and I got confused

#

so now we're back to webpack weirdness

#

are any of your embroider deps out of date?

tepid acorn
#

compat had a new patch release since I started, let me see if that changes things

#

Nope, unfortunately that didn't help

tight knoll
#

are you able to reproduce the issue in a fresh app?

#

maybe it's something we need to throw at runspired

#

(or the embroider folks / me, depending)

tepid acorn
#

I'll try that next, thank you

tepid acorn
#

I've made the min. repro app, using the same ember-cli, ember-source, ember-data and yarn versions – the min. repro "just works", it doesn't throw the error I'm seeing in the big app

tight knoll
#

interesting!

tepid acorn
#

I even diffed the two, built @ember-data/store/-private.js files in the rewritten-packages of Embroider's output and they are exactly the same with minuscule differences

#
<   }, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a;
---
>   }, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer && (Object.defineProperty(i, e, a), a = null), a;
3330c3330
<   }, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a;
---
>   }, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer && (Object.defineProperty(i, e, a), a = null), a;
3492c3492
<   }, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a;
---
>   }, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer && (Object.defineProperty(i, e, a), a = null), a;
#

Is it worth trying to upgrade to Yarn 4? The repro project is obviously a lot smaller, with an order of magnitude less dependencies so I guess it's still possible that there's a dependency resolution problem that Yarn 4 would fix?

tight knoll
#

it's possible

#

what is the output of:

#
npx are-my-node-modules-messed-up
tepid acorn
#

The output is about two dozen errors 😅

#

Of the sort: @fortawesome/ember-fontawesome asked for ember-cli-htmlbars ^5.7.1 but got 6.3.0

#

It seems some of them are related to (yarn) resolutions which were introduced (I guess) to resolve errors

tepid acorn
#

Update: I removed the one dependency that failed yarn install when building the project with Yarn 4. Unfortunately, I still see the same, above getOwner error when loading the app.

#

I'll try with pnpm

tepid acorn
#

So with pnpm I get a different error, thrown by ember-inflector: Could not find module ./package imported from (require)

#

This is the transpiled line that causes trouble: module.exports = {\n name: window.require('./package').name\n};

#
'use strict';

module.exports = {
  name: require('./package').name,
};
#

That's a fairly common pattern, though, is this not supported by pnpm?

#

(I tried explicitly requiring package.json which didn't help)

tight knoll
tight knoll
#

Which version of pnpm did you use?

#

8 or 9+ should be good

#

What's trying to use ember inflector?

tepid acorn
#

I use pnpm 9.5.0

#

There's an app/inflector-rules.js in the app which has this:

#
import Inflector from 'ember-inflector';

Inflector.inflector.uncountable('nps');

export default {};
#

And I assume the import is the one causing the eventual error

tight knoll
#

to confirm , if that file has no import from inflector, does the error go away?

tepid acorn
#

Yes, it does. And then I'm back to the original, getOwner related error 😅

tight knoll
#

interesting

#

can you provide the output of:

pnpm why @embroider/compat
pnpm why @embroider/shared-internals

?

tepid acorn
#

Not yet, I left for vacation but I’ll resume shortly when I’m back. Thanks a lot

tepid acorn
#

@embroider/compat is a direct devDep:

#

devDependencies:
@embroider/compat 3.5.6

#

pnpm why @embroider/shared-internals produces an extremely long output, but there are 3 versions of the add-on in the project

#

2.6.2 is the main one in the project, but there is also several ones at 1.8.3 and one at 0.50.2

#

ember-moment 10.0.0
└─┬ @embroider/addon-shim 0.50.2
└── @embroider/shared-internals 0.50.2

#

There are 4 ones for 1.8.3, required by ember-element-helper, ember-class-names-helper, ember-tooltips and ember-pickr

tepid acorn
#

I made it so that there is only one version of @embroider/shared-internals (2.6.2) and in the process all ember-auto-imports have also been upgraded to v2 (there is version 2.6.3 and 2.7.4) but I still get the same, original getOwner problem

tight knoll
tepid acorn
#

Is npx NullVoxPopuli/are-my-node-modules-messed-up the way to do this?

#

I cloned your repo and did npx ~/code/NullVoxPopuli/are-my-node-modules-messed-up

tight knoll
#

I don't think I published it

#

oh you can npx a file path ? o.o

tepid acorn
#

(After running pnpm install and pnpm prepare)

tepid acorn
tight knoll
#

lol

#

I normally do node ./path/to/file

tepid acorn
#

The above command didn't output anything

tight knoll
#

try using node?

tepid acorn
#

Pointing to the index.js or just the root of the repo?

#

Ok, that prints out many things

#

The project now uses pnpm, by the way, which should do the right thing, should it not?

#

At any rate, I'll nombom and try again with pnpm

#

That didn't change much, I still have about the same number of "asked for X but got Y" lines in the output

#

Of the type:

#

ember-wormhole asked for ember-cli-htmlbars ^5.3.1 but got 6.3.0

tight knoll
tight knoll
#

do you see anything outside of what you've specified in overrides?

tepid acorn
#

Oh, yeah. There are 7 overrides in the project and the command outputs ~30 lines

tepid acorn
#

@tight knoll I wonder if babel might be the culprit (not knowing precisely what role it has in Ember/Embroider apps), here is what I've found.

#

In Embroider's (well, Webpack's) chunk.js output, getOwner is accessed on various modules of the form: _ember_application__WEBPACK_IMPORTED_MODULE_x__.getOwner , where x takes up values of 0, 1, 2, 3, 4, 6, 9. I have yet to check if some of these properties work correctly.

#

The one that gives the error is _ember_application__WEBPACK_IMPORTED_MODULE_2__.getOwner, and here's its assignment:

#
var _ember_application__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @ember/application */ \"../../.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@embroider/babel-loader-9/index.js?{\\\"variant\\\":{\\\"name\\\":\\\"dev\\\",\\\"runtime\\\":\\\"browser\\\",\\\"optimizeForProduction\\\":false},\\\"appBabelConfigPath\\\":\\\"/Users/balint/(...)/ember_app/node_modules/.embroider/rewritten-app/_babel_config_.js\\\",\\\"cacheDirectory\\\":\\\"/private/var/folders/ps/k_qd0wr9757fxt_9jtvcl4n00000gn/T/embroider/webpack-babel-loader\\\"}!../../.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@embroider/webpack/src/virtual-loader.js?f=%2F%40embroider%2Fext-cjs%2F%40ember%2Fapplication&a=%2FUsers%2Fbalint%2Fcode%2F(...)%2F(...)%2Fember_app!\");
#

You can see babel-loader-9 in there which made me think it might have something to do with producing a bad output js? I'm not sure what the role of babel-loader (or other babel packages) is. Do you think this is worth chasing?

tight knoll
#

what is the surrounding code around getOwner?

tepid acorn
#
if (adapter) {\n      return adapter;\n    }\n    let owner
= (0,_ember_application__WEBPACK_IMPORTED_MODULE_2__.getOwner)(this);\n\n    // name specific adapter\n    adapter = owner.lookup(`ad
apter:${normalizedModelName}`);\n
#

Is this what you mean?

#

This the original code that gets compiled to the above:

tight knoll
#

does that version of legacy-compat that you're using declare a peerDependency on ember-source?

tepid acorn
#

Do you mean the @embroider/compat package?

tight knoll
#

nope, ember-data/legacy-compat

tepid acorn
#

Wait, something is not right, the Github ember-data links I sent are for ember-data 5.4.0-alpha.91 while we're still on just 4.11.3 in the project 🤔

tight knoll
#

yea, they have a bug it looks like

#

peerDependencies needs to declare ember-source

#

should be @ember/owner

#

using macroCondition

tight knoll
#

can you pgrade to 4.12.x?

#

unless legacy-compat isn't meant to be used after ember-source@v5

#

might want to summon @vague whale

tepid acorn
#

Well, we tried that a few weeks ago but ultimately rolled back – we'll try again when folks are back from vacation

tight knoll
#

this import should be:

if (macroCondition(dependencySatisfies('ember-source', '>= 4.11.0')) {
  getOwner = importSync('@ember/owner').getOwner;
} else {
  getOwner = importSync('@ember/application').getOwner
}
tepid acorn
#

I tried, however, to upgrade to ember-data 4.12 just to see if that fixes the getOwner error but it didn't

vague whale
#

recommendation historically was to not add ember source as a peer

#

not opposed to adding it for 4.12, we added it later anyway

tepid acorn
#

@vague whale It's an Ember app so it needs to have ember-source . What am I getting wrong?

tight knoll
vague whale
#

We don’t use that

tight knoll
#

yea, sorry, I didn't finish my htought 😅

vague whale
#

and wouldn’t

#

4.12 won’t support 6.x

#

there’s no possible way for it to

tight knoll
#

@ember/application 's getOwner throws a deprecation

vague whale
#

as it should

#

To resolve you upgrade

#

something published 4 years ago throwing a deprecation published a few months ago is hardly surprising

tepid acorn
#

So... how should I proceed? @ember/applications getOwner throws an error (not sure if that comes from a deprecation, but it's a hard error with no info)

tight knoll
tepid acorn
#

That is the deprecation for importing getOwner from @ember/application?

#

I'm not sure I follow. [email protected] was released on Feb 27, 2023, so 1.5 year ago (< 2 years ago), should it not import getOwner from the new place?

tight knoll
#

what's your ember-source version?

tepid acorn
#

Also, the fact that it's deprecated shouldn't make webpack throw an error, should it?

tepid acorn
tight knoll
tepid acorn
#

As per this commit message, import { getOwner } from '@ember/application' should keep working until 6.0, shouldn't it?

tight knoll
#

yeah, that's what I noticed, too

#

which seems to be a dead-end

tepid acorn
#

So the way I could potentially fix this is to patch ember-data to import from @ember/owner, I suppose

tight knoll
#

perhaps!

tepid acorn
#

Even though if everything worked correctly, it shouldn't be needed.

#

But sh*t happens, of course 😆

tight knoll
#

in a blank app, getOwner from @ember/application is importable

#

same with from a v2 addon 🤔

#

I guess we/I need a minimal repro 🤔

tepid acorn
#

So that's weird. I manually rewrote the import { getOwner, setOwner } from '@ember/application' to import from @ember/owner in node_modules/@ember-data/store/addon/-private/store-service.ts (that's the only place this import line was found and it's where the adapterFor definition is, too)

#

I expect to see this change in node_modules/.embroider/rewritten-packages/@ember-data/store.25619ea9/node_modules/@ember-data/store/-private.js which is where it ends up. However, even after cleaning Embroider's cache and rebuilding from scratch, the file in rewritten-packages still has the old import 🤔

tight knoll
#

is your change still there in node_modules?

#

you could also be trolled by cache

#

lemme get you the best command

tepid acorn
#

My change is still there in node_modules/@ember-data but not there in node_modules/.emroider/rewritten-packages

tight knoll
#

can you try a proper pnpm patch? and then try ember-no-cache s

tepid acorn
#

Will do that first thing tomorrow, but gotta wrap up now. Thanks for all the help!

tepid acorn
#

I'm happy to report that properly patching up the @ember-data/store package (so that the getOwner import comes from @ember/owner) fixes the problem!

tepid acorn
#

Just to come back to this, @tight knoll , what should the next step be? Should I try to make a minimal repro? Is this a bug in ember-data or embroider (or sg. else)?

tight knoll
#

I think a minimal repro would be a good place for us to poke around