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

Import attributes support for karma builder #28140

Open
LeonEck opened this issue Jul 30, 2024 · 2 comments
Open

Import attributes support for karma builder #28140

LeonEck opened this issue Jul 30, 2024 · 2 comments

Comments

@LeonEck
Copy link
Contributor

LeonEck commented Jul 30, 2024

Command

test

Description

I am excited about the new loader import attribute option enabled by 24aaf1e

Unfortunately, the karma builder can't deal with the syntax yet and produces an error like this:

> ng test --no-watch --browsers=ChromeHeadless

- Generating browser application bundles (phase: setup)...
✔ Browser application bundle generation complete.

./src/app/app.component.ts - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
SyntaxError: /home/runner/work/import-attribute/import-attribute/src/app/app.component.ts: Support for the experimental syntax 'importAttributes' isn't currently enabled (7:54):

   5 | import { RouterOutlet } from '@angular/router';
   6 | // @ts-expect-error TypeScript cannot provide types based on attributes yet
>  7 | import configFileContent from './app.config.ts' with { loader: 'text' };
     |                                                      ^
   8 | let AppComponent = class AppComponent {
   9 |     title = 'import-attribute';
  10 |     constructor() {

Add @babel/plugin-syntax-import-attributes (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-import-attributes) to the 'plugins' section of your Babel config to enable parsing.

If you already added the plugin for this syntax to your config, it's possible that your config isn't being loaded.
You can re-run Babel with the BABEL_SHOW_CONFIG_FOR environment variable to show the loaded configuration:
	npx cross-env BABEL_SHOW_CONFIG_FOR=/home/runner/work/import-attribute/import-attribute/src/app/app.component.ts <your build command>
See https://babeljs.io/docs/configuration#print-effective-configs for more info.

I created a minimal reproduction here: https://github.com/LeonEck/import-attribute
Failing Test: https://github.com/LeonEck/import-attribute/actions/runs/10165282404/job/28112719062

Are there any plans to extend the support to the karma builder?

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

@HitkoDev
Copy link

HitkoDev commented Oct 9, 2024

Right now it's pretty much impossible to run tests if you use any new features from @angular-devkit/build-angular:application, because Karma and Jest still use Webpack.

@jkrems
Copy link
Contributor

jkrems commented Oct 10, 2024

Yeah, it's an unfortunate intermediate state. The v19 releases contain a "builderMode" option for Karma that allows it to use the application builder. But thats not super helpful for "real" apps right now.

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

No branches or pull requests

4 participants