diff --git a/packages/vite/src/node/__tests__/config.spec.ts b/packages/vite/src/node/__tests__/config.spec.ts index 891ebd1da169de..ee90fb50774f67 100644 --- a/packages/vite/src/node/__tests__/config.spec.ts +++ b/packages/vite/src/node/__tests__/config.spec.ts @@ -1696,8 +1696,8 @@ describe('loadConfigFromFile', () => { expect(messages).toMatchInlineSnapshot(` [ "(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite: - - \`__dirname\` (vite.config.js:3). Use \`import.meta.dirname\` instead - - \`__filename\` (vite.config.js:4). Use \`import.meta.filename\` instead + - \`__dirname\` (vite.config.js:3:29). Use \`import.meta.dirname\` instead + - \`__filename\` (vite.config.js:4:30). Use \`import.meta.filename\` instead Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.", ] `) @@ -1712,7 +1712,7 @@ describe('loadConfigFromFile', () => { expect(messages).toMatchInlineSnapshot(` [ "(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite: - - \`__dirname\` (vite.config.ts:10). Use \`import.meta.dirname\` instead + - \`__dirname\` (vite.config.ts:10:29). Use \`import.meta.dirname\` instead Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.", ] `) @@ -1724,7 +1724,7 @@ describe('loadConfigFromFile', () => { expect(messages).toMatchInlineSnapshot(` [ "(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite: - - import "./helper" without a file extension (vite.config.js:1). Add the file extension + - import "./helper" without a file extension (vite.config.js:1:23). Add the file extension Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.", ] `) @@ -1735,7 +1735,7 @@ describe('loadConfigFromFile', () => { expect(messages).toMatchInlineSnapshot(` [ "(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite: - - import "./plugins" resolves to a directory index (vite.config.js:1). Import the index file directly + - import "./plugins" resolves to a directory index (vite.config.js:1:25). Import the index file directly Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.", ] `) @@ -1746,7 +1746,7 @@ describe('loadConfigFromFile', () => { expect(messages).toMatchInlineSnapshot(` [ "(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite: - - JSON import "./data.json" without import attributes (vite.config.js:1). Add \`with { type: 'json' }\` + - JSON import "./data.json" without import attributes (vite.config.js:1:18). Add \`with { type: 'json' }\` Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.", ] `) @@ -1761,7 +1761,7 @@ describe('loadConfigFromFile', () => { expect(messages).toMatchInlineSnapshot(` [ "(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite: - - import "./foo" resolves to a JSON file (vite.config.js:1). Import it with a \`.json\` extension and \`with { type: 'json' }\` + - import "./foo" resolves to a JSON file (vite.config.js:1:18). Import it with a \`.json\` extension and \`with { type: 'json' }\` Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.", ] `) @@ -1783,7 +1783,7 @@ describe('loadConfigFromFile', () => { expect(messages).toMatchInlineSnapshot(` [ "(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite: - - \`__dirname\` (esm-helper.mjs:1). Use \`import.meta.dirname\` instead + - \`__dirname\` (esm-helper.mjs:1:35). Use \`import.meta.dirname\` instead Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.", ] `) @@ -1794,7 +1794,7 @@ describe('loadConfigFromFile', () => { expect(messages).toMatchInlineSnapshot(` [ "(!) Your Vite config uses features that are unsupported by \`configLoader: 'native'\`, which is planned to become the default in a future major version of Vite: - - ESM syntax in a file loaded as CommonJS (vite.config.js:1). Use a \`.mjs\` extension or set \`"type": "module"\` in the closest package.json + - ESM syntax in a file loaded as CommonJS (vite.config.js:1:1). Use a \`.mjs\` extension or set \`"type": "module"\` in the closest package.json Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.", ] `) diff --git a/packages/vite/src/node/nativeConfigCompat.ts b/packages/vite/src/node/nativeConfigCompat.ts index b2fc57040f295b..0ddbed3c46c948 100644 --- a/packages/vite/src/node/nativeConfigCompat.ts +++ b/packages/vite/src/node/nativeConfigCompat.ts @@ -179,7 +179,8 @@ function describeIncompatibility( item: NativeConfigIncompatibility, root: string, ): string { - const loc = `${normalizePath(path.relative(root, item.file))}:${item.line}` + // 1-based column so terminals can link `file:line:column` to the exact position + const loc = `${normalizePath(path.relative(root, item.file))}:${item.line}:${item.column + 1}` switch (item.type) { case 'dirname': return `\`__dirname\` (${loc}). Use \`import.meta.dirname\` instead`