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

[Bug] Canary fails build with "unable to locate global object" #19431

Closed
simonihmig opened this issue Feb 26, 2021 · 6 comments · Fixed by ember-cli/ember-cli-htmlbars#663
Closed

Comments

@simonihmig
Copy link
Contributor

🐞 Describe the Bug

It seems pretty much all my addons are failing to build as of today at least (scheduled CI runs) with that error at build-time.

🔬 Minimal Reproduction

Just a small sample of addons failing CI:

😕 Actual Behavior

Ember-try scenario for current canary is failing with that build error.

🤔 Expected Behavior

Uh, build successfully? 😆

🌍 Environment

See CI env.

@rwjblue
Copy link
Member

rwjblue commented Feb 26, 2021

This is during template compilation, and I see the changes from ember-cli/ember-cli-htmlbars#660 in the stack. That PR does change what Global’s are available and might be what is causing this. The other changes that I landed here for the template compiler seem somewhat less likely to be the culprit but are possibly combining with that change in a bad way 🤔

@rwjblue
Copy link
Member

rwjblue commented Feb 26, 2021

I think that this detection no longer works (combined with that ember-cli-htmlbars PR):

var globalObj =
typeof globalThis !== 'undefined'
? globalThis
: typeof self !== 'undefined'
? self
: typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: null;
if (globalObj === null) {
throw new Error('unable to locate global object');
}

I will dig in this morning, I thought that globalThis would be defined by the vm context itself but I guess it isn’t.

@rwjblue
Copy link
Member

rwjblue commented Feb 26, 2021

Ya, so basically in Node < 12 globalThis isn't available (either naturally or within a vm.createContext).

I tested the following:

const { inspect } = require('util');
const vm = require('vm');

let script = new vm.Script('(() => globalThis)()');

let context = vm.createContext({});

console.log(script.runInContext(context));

When running on < 12 you get:

ReferenceError: globalThis is not defined
    at evalmachine.<anonymous>:1:8
    at evalmachine.<anonymous>:1:19
    at Script.runInContext (vm.js:135:20)
    at Object.<anonymous> (/Users/rwjblue/src/ember-cli/ember-cli-htmlbars/test.js:8:20)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
    at internal/main/run_main_module.js:21:11

rwjblue added a commit to ember-cli/ember-cli-htmlbars that referenced this issue Feb 26, 2021
This would have caught the error reported in
emberjs/ember.js#19431, we should run with the
lowest supported Node version.
@rwjblue
Copy link
Member

rwjblue commented Feb 26, 2021

@rwjblue
Copy link
Member

rwjblue commented Feb 26, 2021

Oh, also, thank you very much for reporting!

@simonihmig
Copy link
Contributor Author

Np, thanks for the quick fix! 👍

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.

2 participants