Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions examples/custom-webpack/full-cycle-app/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@
"plugins": "prepend"
}
}
},
"json-import-ts": {
"customWebpackConfig": {
"path": "./extra-webpack.config.json-import.ts",
"mergeRules": {
"plugins": "prepend"
}
}
},
"ts-config-json-import": {
"tsConfig": "tsconfig.node-resolution.json",
"customWebpackConfig": {
"path": "./extra-webpack.config.json-import.ts",
"mergeRules": {
"plugins": "prepend"
}
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Configuration } from 'webpack';
// Importing a JSON file from a TypeScript webpack config.
// Requires resolveJsonModule: true to be set — either in the user's tsconfig or
// injected by the builder's ts-node registration.
// When moduleResolution is 'node' and resolveJsonModule is absent, ts-node throws TS2732.
// Regression test for: https://github.com/just-jeb/angular-builders/issues/816
import * as pkg from './package.json';

const _name: string = (pkg as any).name;

export default {
plugins: [],
} as Configuration;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.app.json",
"compilerOptions": {
"moduleResolution": "node"
}
}
8 changes: 8 additions & 0 deletions packages/common/src/load-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ const _tsNodeRegister = (() => {
// Overriding moduleResolution to 'node' (as was done previously) was the root cause of
// issue https://github.com/just-jeb/angular-builders/issues/2025: it prevented TypeScript
// from resolving subpath exports, causing TS2307 errors at build time.
resolveJsonModule: true,
// resolveJsonModule: true is required so that TypeScript webpack configs can import
// JSON files (e.g. `import pkg from './package.json'`). Without this, users on
// moduleResolution:'node' (the default for Angular projects before v17) get TS2732:
// "Cannot find module './foo.json'. Consider using '--resolveJsonModule'".
// This flag is safe to always enable: it has no downside and does not conflict
// with any other moduleResolution mode (node, node16, bundler, etc.).
// Fix for: https://github.com/just-jeb/angular-builders/issues/816
types: [
'node', // NOTE: `node` is added so user configs can use Node.js globals (process, __dirname, etc.)
],
Expand Down
7 changes: 7 additions & 0 deletions packages/custom-webpack/tests/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,11 @@ module.exports = [
app: 'examples/custom-webpack/full-cycle-app',
command: 'yarn build -c bundler-resolution-ts',
},
{
id: 'ts-config-json-module-import',
name: 'custom-webpack: TS config with JSON import (moduleResolution:node)',
purpose: 'Builder loads TypeScript webpack config that imports a JSON file when using moduleResolution:node (regression for #816)',
app: 'examples/custom-webpack/full-cycle-app',
command: 'yarn build -c ts-config-json-import',
},
];
Loading