sveltejs / svelte-loader

Webpack loader for svelte components.
MIT License
594 stars 73 forks source link

syntax error in svelte component causes entire webpack watch process to die #197

Closed elirov closed 2 years ago

elirov commented 2 years ago

if you have an error in your .svelte part (only in the HTML part of it), such as: {if <div/> Then the entire webpack watch process will die instead of just showing a compile error and staying up. It looks like svelte-loader doesn't produce any files, but webpack expects at least some type of output.

We get this in watchpack: TypeError: The "path" argument must be of type string. Received undefined

Due to this, the yarn watch command needs to be restarted constantly.

--- FULL STACK TRACE ---

ERROR in ./tmpls/patient-intake/components/sections/Insurance.svelte Module build failed (from ./node_modules/svelte-loader/index.js): ParseError: Unexpected token at error (/Users/elirov/workspace/xdocs/node_modules/svelte/src/compiler/utils/error.ts:25:16) at Parser$1.error (/Users/elirov/workspace/xdocs/node_modules/svelte/src/compiler/parse/index.ts:101:3) at Parser$1.acorn_error (/Users/elirov/workspace/xdocs/node_modules/svelte/src/compiler/parse/index.ts:94:8) at read_expression (/Users/elirov/workspace/xdocs/node_modules/svelte/src/compiler/parse/read/expression.ts:34:10) at mustache (/Users/elirov/workspace/xdocs/node_modules/svelte/src/compiler/parse/state/mustache.ts:379:22) at new Parser$1 (/Users/elirov/workspace/xdocs/node_modules/svelte/src/compiler/parse/index.ts:53:12) at parse (/Users/elirov/workspace/xdocs/node_modules/svelte/src/compiler/parse/index.ts:218:17) at compile (/Users/elirov/workspace/xdocs/node_modules/svelte/src/compiler/compile/index.ts:94:14) at injectVarsToCode (/Users/elirov/workspace/xdocs/node_modules/svelte-preprocess/dist/transformers/typescript.js:71:45) at mixedImportsTranspiler (/Users/elirov/workspace/xdocs/node_modules/svelte-preprocess/dist/transformers/typescript.js:225:26) @ ./tmpls/patient-intake/components/NewPatientView.svelte 23:0-52 60:17-26 215:2-11 @ ./tmpls/patient-intake/components/MainLayout.svelte 25:0-53 164:22-36 661:2-16 @ ./tmpls/patient-intake/init.js 16:0-69 29:35-45 @ ./src/client/dev/main.js 10:0-61 17:2-16

webpack 5.64.4 compiled with 1 error in 8726 ms node:internal/validators:120 throw new ERR_INVALID_ARG_TYPE(name, 'string', value); ^

TypeError: The "path" argument must be of type string. Received undefined at new NodeError (node:internal/errors:371:5) at validateString (node:internal/validators:120:11) at Object.dirname (node:path:1276:5) at WatcherManager.watchFile (/Users/elirov/workspace/xdocs/node_modules/watchpack/lib/getWatcherManager.js:30:26) at /Users/elirov/workspace/xdocs/node_modules/watchpack/lib/watchpack.js:280:41 at Object.exports.batch (/Users/elirov/workspace/xdocs/node_modules/watchpack/lib/watchEventSource.js:326:3) at Watchpack.watch (/Users/elirov/workspace/xdocs/node_modules/watchpack/lib/watchpack.js:278:20) at NodeWatchFileSystem.watch (/Users/elirov/workspace/xdocs/node_modules/webpack/lib/node/NodeWatchFileSystem.js:107:16) at Watching.watch (/Users/elirov/workspace/xdocs/node_modules/webpack/lib/Watching.js:325:48) at /Users/elirov/workspace/xdocs/node_modules/webpack/lib/Watching.js:303:13 { code: 'ERR_INVALID_ARG_TYPE' }

Node.js v17.1.0 error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

jasonlyu123 commented 2 years ago

From the description of https://github.com/sveltejs/svelte-preprocess/issues/438. I can reproduce this problem. The steps to reproduce: Just clone the webpack template, run setupTypescript and add anything that would cause a markup error to App.svelte

It seems like it has something to do with this line. https://github.com/sveltejs/svelte-loader/blame/5e7853f233d7be5592b0b5fc22da9b4d1a5b0c12/index.js#L81

If there's a preprocessed error. svelte-loader would add the file to webpack's file watcher list. The problem is not all preprocess-error has this property.