最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

angular - Failed to resolve dynamic import - Stack Overflow

programmeradmin4浏览0评论

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.6k8 gold badges72 silver badges117 bronze badges asked Jan 29 at 10:37 DesperadoDesperado 2842 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: './appponent.html',
  styleUrl: './appponent.scss'
})
export class AppComponent {
  title = 'test';

  ngOnInit() {
    const data = import('@fingerprintjs/fingerprintjs/dist/fp');
    console.log(data);
  }
}
发布评论

评论列表(0)

  1. 暂无评论