Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 3cb33fb

Browse files
committed
fix(@ngtools/webpack): fix relative paths in module map imports
Fix #698
1 parent 668fada commit 3cb33fb

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

packages/ngtools/webpack/src/transformers/export_lazy_module_map.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export function exportLazyModuleMap(
4646
return;
4747
}
4848

49-
const relativePath = path.relative(dirName, modulePath).replace(/\\/g, '/');
49+
let relativePath = path.relative(dirName, modulePath).replace(/\\/g, '/');
50+
if (!(relativePath.startsWith('./') || relativePath.startsWith('../'))) {
51+
// 'a/b/c' is a relative path for Node but an absolute path for TS, so we must convert it.
52+
relativePath = `./${relativePath}`;
53+
}
5054
// Create the new namespace import node.
5155
const namespaceImport = ts.createNamespaceImport(ts.createIdentifier(`__lazy_${index}__`));
5256
const importClause = ts.createImportClause(undefined, namespaceImport);

packages/ngtools/webpack/src/transformers/export_lazy_module_map_spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ describe('@ngtools/webpack transformers', () => {
1717
`;
1818
// tslint:disable:max-line-length
1919
const output = tags.stripIndent`
20-
import * as __lazy_0__ from "app/lazy/lazy.module.ts";
21-
import * as __lazy_1__ from "app/lazy2/lazy2.module.ts";
20+
import * as __lazy_0__ from "./app/lazy/lazy.module.ts";
21+
import * as __lazy_1__ from "./app/lazy2/lazy2.module.ts";
2222
export { AppModule } from './app/app.module';
2323
export var LAZY_MODULE_MAP = { "./lazy/lazy.module#LazyModule": __lazy_0__.LazyModule, "./lazy2/lazy2.module#LazyModule2": __lazy_1__.LazyModule2 };
2424
`;
@@ -42,8 +42,8 @@ describe('@ngtools/webpack transformers', () => {
4242
`;
4343
// tslint:disable:max-line-length
4444
const expected = tags.stripIndent`
45-
import * as __lazy_0__ from "app/lazy/lazy.module.ngfactory.ts";
46-
import * as __lazy_1__ from "app/lazy2/lazy2.module.ngfactory.ts";
45+
import * as __lazy_0__ from "./app/lazy/lazy.module.ngfactory.ts";
46+
import * as __lazy_1__ from "./app/lazy2/lazy2.module.ngfactory.ts";
4747
export { AppModule } from './app/app.module';
4848
export var LAZY_MODULE_MAP = { "./lazy/lazy.module#LazyModule": __lazy_0__.LazyModuleNgFactory, "./lazy2/lazy2.module#LazyModule2": __lazy_1__.LazyModule2NgFactory };
4949
`;

packages/ngtools/webpack/src/transformers/multiple_transformers_spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ describe('@ngtools/webpack transformers', () => {
4242

4343
// tslint:disable:max-line-length
4444
const output = tags.stripIndent`
45-
import * as __lazy_0__ from "app/lazy/lazy.module.ngfactory.ts";
46-
import * as __lazy_1__ from "app/lazy2/lazy2.module.ngfactory.ts";
45+
import * as __lazy_0__ from "./app/lazy/lazy.module.ngfactory.ts";
46+
import * as __lazy_1__ from "./app/lazy2/lazy2.module.ngfactory.ts";
4747
4848
import { enableProdMode } from '@angular/core';
4949
import { environment } from './environments/environment';

0 commit comments

Comments
 (0)