angular - Failed to resolve dynamic import - Stack Overflow

admin2025-04-18  3

So I migrated from version 17 to 19, and now the dynamic imports don't work on ng build.

This import

import('@fingerprintjs/fingerprintjs/dist/fp.esm.js')

results in:

TypeError: Failed to resolve module specifier '@fingerprintjs/fingerprintjs/dist/fp.esm.js'

In version 17, this file was bundled like as fp.esm-Q72BNRQR.js and dynamic import was rewritten as

import("./fp.esm-Q72BNRQR.js")

So I migrated from version 17 to 19, and now the dynamic imports don't work on ng build.

This import

import('@fingerprintjs/fingerprintjs/dist/fp.esm.js')

results in:

TypeError: Failed to resolve module specifier '@fingerprintjs/fingerprintjs/dist/fp.esm.js'

In version 17, this file was bundled like as fp.esm-Q72BNRQR.js and dynamic import was rewritten as

import("./fp.esm-Q72BNRQR.js")
Share Improve this question edited Jan 29 at 11:25 DarkBee 15.5k8 gold badges72 silver badges118 bronze badges asked Jan 29 at 10:37 DesperadoDesperado 2822 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Make sure you have installed the necessary typing for using this library:

npm i --save-dev @types/fingerprintjs__fingerprintjs

You should omit the .esm.js and just point to the file without the extension, then it works.

The error could be due to some changes in the angular builder (ESBuild) or version update (tsconfig options updated), I am not sure about this.

import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';

@Component({
  selector: 'app-root',
  imports: [RouterOutlet],
  templateUrl: './app.component.html',
  styleUrl: './app.component.scss'
})
export class AppComponent {
  title = 'test';

  ngOnInit() {
    const data = import('@fingerprintjs/fingerprintjs/dist/fp');
    console.log(data);
  }
}
转载请注明原文地址:http://anycun.com/QandA/1744972271a90232.html