stencil icon indicating copy to clipboard operation
stencil copied to clipboard

bug: renaming a a component file whilst being watched causes an error

Open johnjenkins opened this issue 3 years ago • 4 comments

Prerequisites

Stencil Version

2~ (happens in 2.17.0 but has been present for a long time)

Current Behavior

using the latest version of stencil, whilst within --watch mode, change any component file name (e.g. my-component.tsx to my-new-component.tsx) and stencil fails with an error:

[ ERROR ]  TypeError: Cannot read property 'fileName' of undefined at flattenDiagnosticMessageText
           (.../node_modules/@stencil/core/compiler/stencil.js:1559:45) at
           loadTypeScriptDiagnostic

Expected Behavior

not to fail :)

Steps to Reproduce

npm init stencil > select the component variant. cd NEW_COMPONENT_DIR npm i npm start rename src/components/my-component.tsx to my-new-component.tsx

Code Reproduction URL

just use npm init stencil

Additional Information

No response

johnjenkins avatar Jun 28 '22 15:06 johnjenkins

Thanks @johnjenkins! I was able to confirm this has been around since at least v2.7.0. Labelling this so that it gets ingested into the backlog

rwaskiewicz avatar Jun 28 '22 16:06 rwaskiewicz

Hi @johnjenkins!

I think it is a valid error and that it only warns you that something is wrong in the test file.

If you correct the path in src/components/my-component/my-component.spec.ts, the error disappears and the browser reloads without problems:

2c2
< import { MyComponent } from './my-component';
---
> import { MyComponent } from './my-new-component';

I think this issue could be closed or, perhaps, renamed to "Test files should be ignored in browser transpilation with npm start". But personally I prefer the build to fail if there is a test failure.

linuxonrails avatar Jul 12 '22 12:07 linuxonrails

hey @linuxonrails,

thanks for your input! however, even when no tests exist in a project, I am able to reproduce this issue. the root cause has to do with a race condition where the dev server isn't able to understand that the file has changed it's name

rwaskiewicz avatar Jul 13 '22 17:07 rwaskiewicz

Just a quick update on this, I just opened a small PR (#3627) which fixes a bit of diagnostic handling code where we were accessing a property on a possibly-undefined value without checking.

After fixing that issue one thing I'm consistently running into is this upstream issue in TypeScript: https://github.com/microsoft/TypeScript/issues/43838

alicewriteswrongs avatar Sep 21 '22 16:09 alicewriteswrongs