Parse error: Snowpack fails to parse first tsx file for imports #2958
-
I had a working build sometime mid-last-week, both on 3.0.13 and 3.1.0-pre-something. I'm now just getting this:
As soon as I run the build (both in dev and build mode). As in, this is the first js/ts/tsx file it tries to parse. Turning on verbose exposes this:
I'm not sure what's going wrong here, but seems like Snowpack is simply incorrectly believing that the TS file is JS. I want to say that something has changed in my code since I can't even get things to work with 3.0.13 anymore, but I just can't figure out what. What could cause something like this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Looks like it's intended to be parsed as JS, and that it's the |
Beta Was this translation helpful? Give feedback.
-
Snowpack config: const { definitions } = require('./scripts/globalDefinitions');
const httpProxy = require('http-proxy');
const proxy = httpProxy.createServer({ target: 'http://localhost:60000' });
// Create RegEx replace patterns for all of the global definitions
const subs = Object.entries(definitions).map(([k, v]) => ({
from: new RegExp(k, 'g'),
to: v,
}));
/** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
alias: {
src: './src',
},
buildOptions: {},
devOptions: {},
mount: {
public: { static: true, url: '/' },
src: { url: '/dist' },
},
optimize: {},
packageOptions: {},
plugins: [
'@snowpack/plugin-react-refresh',
'@snowpack/plugin-typescript',
[
'@snowpack/plugin-sass',
{
compilerOptions: {
loadPath: './',
},
},
],
'snowpack-plugin-svgr',
[
'@snowpack/plugin-run-script',
{
cmd: 'eslint --ext=.js,.jsx,.ts,.tsx --color $PWD',
watch: 'esw -w --clear src --ext .js,jsx,.ts,.tsx --color $PWD',
},
],
[
'snowpack-plugin-replace',
{
list: subs,
},
],
],
routes: [
{
dest: (req, res) => {
// remove /api prefix (optional)
req.url = req.url.replace(/^\/api/, '');
proxy.web(req, res);
},
src: '/api/.*',
},
],
};
{
"compilerOptions": {
"module": "es2020",
"target": "es2019",
"moduleResolution": "node",
"jsx": "preserve",
"baseUrl": "./",
/* paths - import rewriting/resolving */
"paths": {
// If you configured any Snowpack aliases, add them here.
// Add this line to get types for streaming imports (packageOptions.source="remote"):
// "*": [".snowpack/types/*"]
// More info: https://www.snowpack.dev/guides/streaming-imports
},
/* noEmit - Snowpack builds (emits) files, not tsc. */
"noEmit": true,
/* Additional Options */
"strict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
// TODO: Enable and fix this eventually
"importsNotUsedAsValues": "remove",
"noImplicitAny": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"include": [
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"build/**/*",
"public/**/*"
]
} |
Beta Was this translation helpful? Give feedback.
-
Turns out the replacements I was doing with |
Beta Was this translation helpful? Give feedback.
Turns out the replacements I was doing with
snowpack-plugin-replace
went wrong after a refactor of that code. E.g. things likefoo(BAR)
would be turned intofoo(hello world)
instead offoo("hello world")
🤦 , case closed.