Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ember 4.1+ || Error while processing route: ember window.Ember is undefined -- related: can't access lexical declaration '__WEBPACK_DEFAULT_EXPORT__' before initialization #1038

Closed
NullVoxPopuli opened this issue Dec 5, 2021 · 9 comments · Fixed by #1053

Comments

@NullVoxPopuli
Copy link
Collaborator

This is a preliminary issue, but cropped up -- not sure why yet.

There is only one occurrence of window.Ember:
image
which comes from:
image
which is defined here:

if (
macroCondition(
dependencySatisfies('ember-source', '>=3.27.0-canary || >=3.27.0-beta')
)
) {
// new enough ember has a real module we can import
runtime = importSync('@glimmer/runtime');
} else {
// older ember has its own internal loader
runtime = window.Ember.__loader.require('@glimmer/runtime');
}

Here is the code / error:

Error while processing route: index window.Ember is undefined ../node_modules/@embroider/util/ember-private-api.js@http://localhost:4200/assets/chunk.4c6a1d188e8b66e667de.js:32527:3
__webpack_require__@http://localhost:4200/assets/chunk.366fbe0dd169a8169677.js:23:42
../node_modules/@embroider/util/index.js@http://localhost:4200/assets/chunk.4c6a1d188e8b66e667de.js:32618:95
__webpack_require__@http://localhost:4200/assets/chunk.366fbe0dd169a8169677.js:23:42

and related error:

can't access lexical declaration '__WEBPACK_DEFAULT_EXPORT__' before initialization

image

@NullVoxPopuli
Copy link
Collaborator Author

if I revert back to Ember 4.0.1 the error goes away, so this seems to be an issue with dependencySatisfies?

NullVoxPopuli added a commit to NullVoxPopuli/limber that referenced this issue Dec 6, 2021
@NullVoxPopuli
Copy link
Collaborator Author

I confirm the fix by changing the macroCondition to just true in node_modules. but I am unable to get 4.1.0-beta or 4.2.0-alpha to match the dependencySatisfies

NullVoxPopuli added a commit to NullVoxPopuli/embroider that referenced this issue Dec 6, 2021
NullVoxPopuli added a commit to NullVoxPopuli/limber that referenced this issue Dec 6, 2021
ember-cli-babel ruins lives :(
(or maybe just babel)

Blocked by: NullVoxPopuli/ember-statechart-component#149
which is in-turn blocked by: emberjs/ember-cli-babel#419
which is then blocked by ember-data... *for some reason*.
(I don't use ember-data here, so idgaf)

Further work is blocked by embroider-build/embroider#1038
@NullVoxPopuli
Copy link
Collaborator Author

I tried adding >= 4.0.0 to the dependencySatisfies condition, but:
image
still false.

@Windvis
Copy link
Collaborator

Windvis commented Dec 6, 2021

I don't think it's an issue with the SemVer version range itself. includePrerelease is set so it should also match the prerelease versions.

Can you debug the dependencySatisfies macro to see from where it returns false?

@NullVoxPopuli
Copy link
Collaborator Author

adding console.logs in node_modules seems to not show anything 🤷

@NullVoxPopuli
Copy link
Collaborator Author

NullVoxPopuli commented Dec 7, 2021

ah ha!

if (err.code !== 'MODULE_NOT_FOUND') {

I'm falling in to this branch --

unable to resolve package ember-source from /tmp/embroider/66dd2e/node_modules/@embroider/util
unable to resolve package ember-source from /tmp/embroider/66dd2e/node_modules/ember-focus-trap

(but multiple times)

at PackageCache.resolve (/✂️/limber/node_modules/@embroider/shared-internals/src/package-cache.js:29:21)
    at dependencySatisfies (/✂️/limber/node_modules/@embroider/macros/src/babel/dependency-satisfies.js:40:36)
    at Evaluator.evaluateMacroCall (/✂️/limber/node_modules/@embroider/macros/src/babel/evaluate-json.js:319:81)
    at PluginPass.enter (/✂️/limber/node_modules/@embroider/macros/src/babel/macros-babel-plugin.js:127:71)
    at newFn (/✂️/limber/node_modules/@babel/traverse/lib/visitors.js:177:21)
    at NodePath._call (/✂️/limber/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/✂️/limber/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/✂️/limber/node_modules/@babel/traverse/lib/path/context.js:100:31)
    at TraversalContext.visitQueue (/✂️/limber/node_modules/@babel/traverse/lib/context.js:103:16)

@NullVoxPopuli
Copy link
Collaborator Author

@ef4 would it make sense to fall back to the app's ember-source if we get in to this branch?

@ef4
Copy link
Contributor

ef4 commented Dec 13, 2021

In older APIs that we're trying not to break we allow that kind of fallback. But this is new API and we're trying to be strict.

Instead we should list ember-source as a peerDep of @embroider/util, so that it's always resolvable regardless of hoisting / monorepos / alternative package managers.

@NullVoxPopuli
Copy link
Collaborator Author

Here is my work-around for now:

// @ts-check
'use strict';

const path = require('path');
const fs = require('fs/promises');

const modules = path.join(__dirname, 'node_modules');

/**
  * These are patches to packages where things work for
  * this project, but I don't yet know what the proper way to fix the issue
  * for real is.
  */
async function start() {
  await patchEmbroiderIssue1038();
}

async function patchEmbroiderIssue1038() {
  console.log('Patching @embroider/util due to https://github.com/embroider-build/embroider/issues/1038');

  let emberPrivateApi = path.join(modules, '@embroider/util/addon/ember-private-api.js');
  let fileBuffer = await fs.readFile(emberPrivateApi);
  let file = fileBuffer.toString();

  // the macro-condition for this file doesn't work because embroider can't find
  // ember-source.
  // since we know that
  file = file.replace(/macroCondition\(/, 'true || (');

  await fs.writeFile(emberPrivateApi, file);
}

start();

and then in package.json:

  "scripts": {
    "prepare": "node patch-packages.js",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants