Build started failing with "Module parse failed: Unexpected token" #2810
Replies: 3 comments 1 reply
-
I fixed it by patching webpack config like this: /** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
mount: {
public: { url: '/', static: true },
src: { url: '/dist' },
},
plugins: [
[
'@snowpack/plugin-webpack',
{
extendConfig: (config) => {
// FIXES https://github.com/snowpackjs/snowpack/discussions/2810
config.module.rules.find(
(rule) =>
rule &&
rule.use &&
rule.use.find((use) => {
if (
!use ||
!use.loader ||
!use.loader.includes('babel-loader')
) {
return null;
}
use.options.plugins = (use.options.plugins || []).concat([
'@babel/plugin-proposal-optional-chaining',
]);
return use;
}),
);
return config;
},
},
],
'@snowpack/plugin-react-refresh',
'@snowpack/plugin-dotenv',
'@snowpack/plugin-typescript',
],
install: [],
installOptions: {},
devOptions: {},
buildOptions: {},
proxy: {},
alias: {
'@src': './src',
},
}; |
Beta Was this translation helpful? Give feedback.
-
Related issue: #2354 (I see that @alexeychikk already linked from that issue to here, I'm just making it doubly-linked. 😄) |
Beta Was this translation helpful? Give feedback.
-
I spent hours chasing an issue that I thought was related to this, but it turned out to be webpack/webpack#12960. It looked like Babel was miscompiling the optional chaining operator - which I assumed was a bug in Snowpack's configuration - but it's actually a Webpack bug. Hope this message saves someone else the work that I did! I've worked around this for now by setting |
Beta Was this translation helpful? Give feedback.
-
I haven't changed anything in my configs or deps. But after the latest clean
npm i
my build started failing with:The particular line that fails in my code is this optional chaining syntax:
abortFn.current?.();
My
tsconfig.json
:My snowpack config:
UPD 1:
I think the issue here is that snowpack ignores
"target": "ES2019"
of mytsconfig.json
and therefore not compiles optional chaining syntax to a vanilla js. I also tried to pass args explicitly['@snowpack/plugin-typescript', { args: '--project tsconfig.json' }]
but it has no effect.Beta Was this translation helpful? Give feedback.
All reactions