emberjs / ember.js

Ember.js - A JavaScript framework for creating ambitious web applications
https://emberjs.com
MIT License
22.46k stars 4.22k forks source link

[5.10] Can't import the template-compiler #20718

Open boris-petrov opened 1 week ago

boris-petrov commented 1 week ago

🐞 Describe the Bug

Upgrading from 5.9 to 5.10 and importing the template compiler leads to:

Uncaught TypeError: Application.initializer is not a function
    at ember-template-compiler.js:2100:1
    at ember-template-compiler.js:2108:1

🔬 Minimal Reproduction

ember new --pnpm ember-template-compiler-bug
cd ember-template-compiler-bug
# add `app.import('vendor/ember/ember-template-compiler.js');` to `ember-cli-build.js`
ember test

😕 Actual Behavior

That error.

🤔 Expected Behavior

No error.

🌍 Environment

NullVoxPopuli commented 1 week ago

I've reproduced the issue over at https://github.com/NullVoxPopuli/limber/pull/1787

This is a runtime error

NullVoxPopuli commented 1 week ago

so far, it seems the the fix is to remove the app.import

boris-petrov commented 1 week ago

I'm confused... how can I remove it if I need it?

NullVoxPopuli commented 1 week ago

I'm confused... how can I remove it if I need it?

apologies, I'm still working this out,

A couple tests,

NullVoxPopuli commented 1 week ago

for hbs-only compiling, I use:

const { precompileJSON } = importSync('@glimmer/compiler');
const { getTemplateLocals } = importSync('@glimmer/syntax');

and for gjs compiling, I use:

const compiler = importSync('ember-source/dist/ember-template-compiler.js');

because babel-plugin-ember-template-compilation asks that of me in its API. but really it needs:

So, looking at the source for the template-compiler, https://github.com/emberjs/ember.js/blob/main/packages/ember-template-compiler/lib/public-api.ts, I can re-create this, using the imports that do happen to work:

export { preprocess as _preprocess, print as _print } from '@glimmer/syntax';
export { default as precompile } from './system/precompile';
export { buildCompileOptions as _buildCompileOptions } from './system/compile-options';

precompile is ultimately:

import { precompile as glimmerPrecompile } from '@glimmer/compiler';

export default function precompile(templateString, options = {}){
  return glimmerPrecompile(templateString, compileOptions(options));
}

and yadda yadda for the compiler options -- for the REPL purposes, it's possible I don't need that half that stuff -- since the REPL doesn't have as strict of compatibility requirements as ember-source does.

but anyyyyway -- the crux of the problem is this line:

https://github.com/emberjs/ember.js/blob/0da8387a91d6c3ca0c81238e3a3775ce459cb298/packages/ember-template-compiler/lib/system/initializer.ts#L12

Something has gone wrong with teh @ember/application export.

I'm confused... how can I remove it if I need it?

it looks like you don't need app.import if you did importSync to get the real file before