Receiving parse errors when bundling project with Webpack. In particular, it does not look like the source-map-loader Webpack loader is correctly parsing the source maps in the project.
devtool: 'source-map',
module : {
rules : [
{
test: /\.tsx?$/,
use: ['awesome-typescript-loader']},
{
test: /\.scss$/,
use: [
{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "sass-loader"
}
]
},
{
test: /\.css$/,
use: [
{
loader: "style-loader"
}, {
loader: "css-loader"
}
]
},
{
test: /\.woff($|\?)|\.woff2($|\?)|\.ttf($|\?)|\.eot($|\?)/,
use: ['url-loader']
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
'url-loader',
'image-webpack-loader'
]
},
{
test: /\.js\.map$/,
use: {
loader: 'source-map-loader'
},
},
{
test: /\.js$/,
use: {
loader: 'source-map-loader'
},
}
]
}
class Home extends React.Component {
componentDidMount() {
var term = new Terminal();
// Exposes the terminal in an existing DOM object.
term.open(document.getElementById('xterm-container'));
}
render() {
return (
<div id="xterm-container">
</div>
);
}
}
WARNING in ./node_modules/xterm/lib/addons/search/search.js.map
Module parse failed: /home/jack/Projects/C290/website/node_modules/source-map-loader/index.js!/home/jack/Projects/C290/website/node_modules/xterm/lib/addons/search/search.js.map Unexpected token (1:10)
You may need an appropriate loader to handle this file type.
| {"version":3,"sources":["../../../src/addons/search/search.ts"],"names":[],"mappings":";;AAIA,+CAA8C;AAQ9C,CAAC,UAAU,KAAK;IACd,EAAE,CAAC,CAAC,UAAU,IAAI,MAAM,CAAC,CAAC,CAAC;QAIzB,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;IAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC;QAIrE,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;IACjD,CAAC;IAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,MAAM,IAAI,UAAU,CAAC,CAAC,CAAC;QAIvC,MAAM,CAAC,CAAC,aAAa,CAAC,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;AACH,CAAC,CAAC,CAAC,UAAC,QAAa;IAOf,QAAQ,CAAC,SAAS,CAAC,QAAQ,GAAG,UAAS,IAAY;QACjD,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;YACxB,IAAI,CAAC,YAAY,GAAG,IAAI,2BAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,2BAA2B,CAAC,CAAC;QACnF,CAAC;QACD,MAAM,CAAgB,IAAI,CAAC,YAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1D,CAAC,CAAC;IAQF,QAAQ,CAAC,SAAS,CAAC,YAAY,GAAG,UAAS,IAAY;QACrD,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;YACxB,IAAI,CAAC,YAAY,GAAG,IAAI,2BAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,2BAA2B,CAAC,CAAC;QACnF,CAAC;QACD,MAAM,CAAgB,IAAI,CAAC,YAAa,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC9D,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","file":"search.js","sourceRoot":"."}
@ ./node_modules/xterm/lib/addons ^\.\/.*$
@ ./node_modules/xterm/lib/xterm.js
@ ./client/hof-content.tsx
@ ./client/hof.tsx
@ ./client/app.tsx
@ ./client/main.tsx
@ multi (webpack)-dev-server/client?http://localhost:3000 webpack-dev-server/client?http://localhost:3000/ ./client/main.tsx
WARNING in ./node_modules/xterm/lib/addons/search/SearchHelper.js.map
Module parse failed: /home/jack/Projects/C290/website/node_modules/source-map-loader/index.js!/home/jack/Projects/C290/website/node_modules/xterm/lib/addons/search/SearchHelper.js.map Unexpected token (1:10)
You may need an appropriate loader to handle this file type.
| {"version":3,"file":"SearchHelper.js","sources":["../../../src/addons/search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term.js
@ ./client/hof-content.tsx
@ ./client/hof.tsx
@ ./client/app.tsx
@ ./client/main.tsx
@ multi (webpack)-dev-server/client?http://localhost:3000 webpack-dev-server/client?http://localhost:3000/ ./client/main.tsx
The project works fine if I redirect the main option in the package.json to dist/xterm.js and also works if I delete the search.js.map and SearchHelper.js.map files. However, I would ideally like to preserve the package's integrity to maintain portability to other devices.
Try changing this:
{
test: /\.tsx?$/,
use: ['awesome-typescript-loader']},
to
{
test: /\.(tsx|ts)?$/,
use: ['awesome-typescript-loader']},
Or try ignoring the node_modules folder(which should be done anyway):
{
test: /\.(tsx|ts)?$/,
exclude: /node_modules/,
use: ['awesome-typescript-loader']},
Thanks for the tip. I changed that but it still didn't work. However, I think I know why it breaks.
The /lib/xterm.js file has variable dependencies in the Terminal.loadAddon function (line 477). The way that webpack works is to go ahead and bundle together all possible resolutions to the variable dependency; in this case it tries to include every file in the the addons folder.
It gets tripped up on the .min.js files because webpack normally only accesses these files through their corresponding .js (or other format) file.
My dumb brain said that obviously we should process the .js.map files with the source-map-loader but that's really just for .js files, hence the error.
Changing this
{
test: /\.js\.map$/,
use: {
loader: 'source-map-loader'
},
},
to
{
test: /\.js\.map$/,
use: {
loader: 'file-loader'
},
},
will just bundle the file as-is without trying to process it in any way.
It just tripped me up because apparently this is a pretty uncommon problem since noone really intentionally loads .js.map files with a require statement directly. Hence the 2 hours of fruitless google searches on the issue.
Now the real question is how to get it so that the addon files don't get bundled by webpack and cause unnecessary bundle bloat and funky errors. I don't know if it would be better to do a PR or if there is some webpack config option that I am missing.
@jclangst thanks for reporting this. A PR is definitely welcome if there is a transparent way of fixing this.
Just mentioning that we are using the v3 branch, as base now.
I had the very same issue, even though I wasn't using source-map-loader. I was able to get rid of the warnings by using the webpack ignore-loader as seen in this Stackoverflow post. This is the line I included in module.rules:
{ test: /node_modules.+xterm.+\.map$/, loader: 'ignore-loader' },
Possibly this aproach could also be used to prevent webpack from bundling the other addons.
Here's another possible solution: use webpack.IngorePlugin
new webpack.IgnorePlugin(/^\.\/.*js.map$/ ,/.*xterm\/lib\/addons/),
I'm consolidating all bundling/loadAddon related issues into https://github.com/sourcelair/xterm.js/issues/1018, please comment on that issue if you have thoughts :smiley:
Most helpful comment
Thanks for the tip. I changed that but it still didn't work. However, I think I know why it breaks.
The
/lib/xterm.jsfile has variable dependencies in theTerminal.loadAddonfunction (line 477). The way that webpack works is to go ahead and bundle together all possible resolutions to the variable dependency; in this case it tries to include every file in the theaddonsfolder.It gets tripped up on the
.min.jsfiles because webpack normally only accesses these files through their corresponding.js(or other format) file.My dumb brain said that obviously we should process the
.js.mapfiles with thesource-map-loaderbut that's really just for.jsfiles, hence the error.Changing this
to
will just bundle the file as-is without trying to process it in any way.
It just tripped me up because apparently this is a pretty uncommon problem since noone really intentionally loads
.js.mapfiles with arequirestatement directly. Hence the 2 hours of fruitless google searches on the issue.Now the real question is how to get it so that the addon files don't get bundled by webpack and cause unnecessary bundle bloat and funky errors. I don't know if it would be better to do a PR or if there is some webpack config option that I am missing.