-
-
Notifications
You must be signed in to change notification settings - Fork 433
Thrown Errors have wrong line numbers #882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I believe this is a webpack issue rather than a ts-loader one. If it is a ts-loader one then we'd happily welcome PRs that improve things! |
But, If you would like to provide help or solution, it will very thankful. |
I believe it's a ts-loader issue because it doesn't happen with |
Consensus on this thread seems to be pointing towards it being an issue on the ts-loader side, and persists to this day. Could you kindly reopen this issue for visibility's sake? |
Reopened - if someone would like to work on this we'll happily look at a PR |
Also in the case that anyone comes across this issue, I managed to find a temporary workaround that compiles the typescript files first and then using webpack on the compiled files, bypassing ts-loader (and also a short script that adds in aliases from tsconfig paths to replace the tsconfig-paths-webpack-plugin, but note that the script is pretty specific to my usecase and you should probably just manually type it out if you have complex path aliases) webpack.config.js const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const paths = require('require-json5')('./tsconfig.json').compilerOptions.paths;
const alias = {};
Object.entries(paths).forEach(([key, value]) => {
alias[key.replace('/*', '')] = value.map((v) =>
path.resolve(__dirname, v.replace('/*', '').replace('src', 'build'))
);
});
console.log(alias);
module.exports = {
mode: 'production',
target: 'node',
devtool: 'inline-source-map',
entry: './build/app.js',
externals: [nodeExternals()],
externalsPresets: { node: true },
output: {
clean: true,
filename: 'app.js',
path: path.resolve(__dirname, 'dist'),
devtoolModuleFilenameTemplate: '[resource-path]',
},
resolve: {
extensions: ['.js'],
alias,
},
module: {
rules: [{ test: /\.js$/, enforce: 'pre', use: ['source-map-loader'] }],
},
plugins: [
new CopyPlugin({
patterns: [
{
from: '(package.json|ecosystem.config.js|.npmrc)',
info: { minimized: true },
noErrorOnMissing: true,
},
],
}),
],
}; tsconfig.json {
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 16",
"compilerOptions": {
/* Basic Options */
"target": "es2020",
"module": "commonjs",
"outDir": "build",
"inlineSourceMap": true,
"removeComments": false,
"lib": ["es2020"],
/* Strict Type-Checking Options */
"strict": true,
"noImplicitOverride": true,
"useUnknownInCatchVariables": false,
/* Additional Checks */
"strictNullChecks": true,
/* Module Resolution Options */
"baseUrl": ".",
"esModuleInterop": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"types": ["node"],
"paths": {
"@/*": ["src/*"],
"~/*": ["src/types/*"]
},
"typeRoots": ["node_modules/@types"]
},
/* Advanced Options */
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"ts-node": {
"files": true
}
} package.json {
"main": "app.js",
"scripts": {
"prebuild": "npx tsc",
"build": "npx webpack",
"postbuild": "npx rimraf build"
}
} Source file structure .
├── src
│ ├── app.ts
│ ├── util.ts
│ └── @
│ ├──── A.ts
│ └──── B.ts
├── tsconfig.json
├── package.json
└── webpack.config.js Prebuild file structure .
├── build
│ ├── app.js
│ ├── util.js
│ └── @
│ ├──── A.js
│ └──── B.js
├── src
│ ├── app.ts
│ ├── util.ts
│ └── @
│ ├──── A.ts
│ └──── B.ts
├── tsconfig.json
├── package.json
└── webpack.config.js Postbuild file structure .
├── dist
│ ├── app.js
│ └── package.json
├── src
│ ├── app.ts
│ ├── util.ts
│ └── @
│ ├──── A.ts
│ └──── B.ts
├── tsconfig.json
├── package.json
└── webpack.config.js |
UPDATE After alot of tweaking, I've found that by changing webpack.config.js const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin');
module.exports = {
mode: 'production',
target: 'node',
devtool: 'inline-source-map',
entry: 'src/app.ts',
externals: [nodeExternals()],
externalsPresets: { node: true },
output: {
clean: true,
filename: 'app.js',
path: path.resolve(__dirname, 'dist'),
devtoolModuleFilenameTemplate: '[resource-path]',
},
resolve: {
extensions: ['.ts', '.js'],
plugins: [new TsconfigPathsPlugin({ extensions: ['.ts'] })],
},
module: {
rules: [
{
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
plugins: [
new CopyPlugin({
patterns: [
{
from: '(package.json|ecosystem.config.js|.npmrc)',
info: { minimized: true },
noErrorOnMissing: true,
},
],
}),
],
}; tsconfig.json {
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 16",
"compilerOptions": {
/* Basic Options */
"target": "es2020",
"module": "commonjs",
"outDir": "build",
"sourceMap": true,
"removeComments": true,
"lib": ["es2020"],
/* Strict Type-Checking Options */
"strict": true,
"noImplicitOverride": true,
"useUnknownInCatchVariables": false,
/* Additional Checks */
"strictNullChecks": true,
/* Module Resolution Options */
"baseUrl": ".",
"esModuleInterop": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"types": ["node"],
"paths": {
"@/*": ["src/*"],
"~/*": ["src/types/*"]
},
"typeRoots": ["node_modules/@types"]
},
/* Advanced Options */
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"ts-node": {
"files": true
}
} package.json {
"main": "app.js",
"scripts": {
"build": "npx webpack",
"start": "node ."
}
} @johnnyreilly hope this helps with finding a more user-friendly solution to this issue, and perhaps documenting this somewhere in the meantime as a workaround |
Would you like to submit a docs PR? That'd be super helpful! Thanks for writing up your findings here |
I’ll give it a go this morning as well , will make sure it works for us too |
we already had sourceMap: true sadly, didnt work for us , here is our implementation of webpack
with tsconfig
|
@lukepolo could you try changing |
yup that will work for development! Production still wont work as we cannot release our source map along with the app. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Closing as stale. Please reopen if you'd like to work on this further. |
Expected Behaviour
any of the source-map options to tell me where errors actually happened (or throwed to be more exact)
Actual Behaviour
the lines on these error messages have some offset to their actual lines. sometimes printed line numbers are even higher than the actual LoC in the file.
tried the settings from README 1:1 and stuff like
'cheap-module-eval-source-map'
and what-not as sourcemap, always an offset.webpack.conf.js
error output
BattleGen1.ts
The text was updated successfully, but these errors were encountered: