Skip to content

Commit 8f7d862

Browse files
committed
fix(webpack): opt out of typescript auto resolve (#9521)
1 parent 2ee0453 commit 8f7d862

6 files changed

Lines changed: 26 additions & 0 deletions

File tree

integration-tests/webpack/build-and-test-git-tags.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { spawnSync } = require('child_process')
99
const assert = require('assert')
1010
const webpack = require('webpack')
1111
const DatadogWebpackPlugin = require('../../webpack') // dd-trace/webpack
12+
const experiments = require('./webpack-experiments')
1213

1314
const OUTFILE = path.join(__dirname, 'git-tags-out.js')
1415

@@ -17,6 +18,7 @@ const compiler = webpack({
1718
entry: path.join(__dirname, 'basic-test.js'),
1819
target: 'node',
1920
externalsType: 'commonjs',
21+
...(experiments && { experiments }),
2022
output: {
2123
filename: 'git-tags-out.js',
2224
path: __dirname,

integration-tests/webpack/build-and-test-minify.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const path = require('path')
88
const assert = require('assert')
99
const webpack = require('webpack')
1010
const DatadogWebpackPlugin = require('../../webpack') // dd-trace/webpack
11+
const experiments = require('./webpack-experiments')
1112

1213
const OUTFILE = path.join(__dirname, 'minify-out.js')
1314

@@ -17,6 +18,7 @@ try {
1718
// optimization.minimize is enabled by default in production mode
1819
entry: path.join(__dirname, 'basic-test.js'),
1920
target: 'node',
21+
...(experiments && { experiments }),
2022
output: {
2123
filename: 'minify-out.js',
2224
path: __dirname,

integration-tests/webpack/build-and-test-openfeature.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const assert = require('assert')
2323
const { execFileSync } = require('child_process')
2424
const webpack = require('webpack')
2525
const DatadogWebpackPlugin = require('../../webpack') // dd-trace/webpack
26+
const experiments = require('./webpack-experiments')
2627

2728
const ENTRY = path.join(__dirname, 'openfeature-app.js')
2829
const FLAGGING_PROVIDER = path.join('openfeature', 'flagging_provider')
@@ -49,6 +50,7 @@ function build (outfile, plugins) {
4950
entry: ENTRY,
5051
target: 'node',
5152
externalsType: 'commonjs',
53+
...(experiments && { experiments }),
5254
output: { filename: path.basename(outfile), path: path.dirname(outfile), hashFunction: 'sha256' },
5355
externals: EXTERNALS,
5456
plugins,

integration-tests/webpack/build-and-test-skip-external.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const path = require('path')
88
const assert = require('assert')
99
const webpack = require('webpack')
1010
const DatadogWebpackPlugin = require('../../webpack') // dd-trace/webpack
11+
const experiments = require('./webpack-experiments')
1112

1213
const OUTFILE = path.join(__dirname, 'skip-external-out.js')
1314

@@ -16,6 +17,7 @@ const compiler = webpack({
1617
entry: path.join(__dirname, 'skip-external.js'),
1718
target: 'node',
1819
externalsType: 'commonjs',
20+
...(experiments && { experiments }),
1921
output: {
2022
filename: 'skip-external-out.js',
2123
path: __dirname,

integration-tests/webpack/build.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
const path = require('path')
77
const webpack = require('webpack')
88
const DatadogWebpackPlugin = require('../../webpack') // dd-trace/webpack
9+
const experiments = require('./webpack-experiments')
910

1011
const compiler = webpack({
1112
mode: 'development',
1213
entry: path.join(__dirname, 'basic-test.js'),
1314
target: 'node',
1415
externalsType: 'commonjs',
16+
...(experiments && { experiments }),
1517
output: {
1618
filename: 'out.js',
1719
path: __dirname,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict'
2+
3+
const webpackPkg = require('webpack/package.json')
4+
5+
// webpack 5.107.0 introduced `experiments.typescript` (opt-in), and 5.109.0 defaults it to
6+
// "auto". On Node.js >= 22.6 (where `module.stripTypeScriptTypes` exists), "auto" turns the
7+
// experiment on and sets `resolve.tsconfig = true`, making enhanced-resolve walk up to each
8+
// resolved package's own tsconfig.json. Some published packages (e.g. `side-channel`) ship a
9+
// tsconfig.json that `extends` a devDependency-only config package (`@ljharb/tsconfig`) that
10+
// isn't installed, so resolution fails with a "Module not found" error unrelated to
11+
// TypeScript. Explicitly disable the experiment where the option exists; older webpack
12+
// versions don't recognize the key at all, so it must not be set for those.
13+
const [major, minor] = webpackPkg.version.split('.').map(Number)
14+
const supportsTypescriptExperiment = major > 5 || (major === 5 && minor >= 107)
15+
16+
module.exports = supportsTypescriptExperiment ? { typescript: false } : undefined

0 commit comments

Comments
 (0)