stencil icon indicating copy to clipboard operation
stencil copied to clipboard

bug: Build succeeds first time, but fails second time

Open petercmuc opened this issue 6 months ago • 6 comments
trafficstars

Prerequisites

Stencil Version

4.*

Current Behavior

With an incorrect import path to a typescript interface the first build succeeds. This happens when the import path is transpiled to the component.d.ts type definition.

Expected Behavior

All builds with incorrect import paths should fail

System Info


Steps to Reproduce

See the Git repo for reproduction...

In a component use an event emitter which uses an interface:

import { MyType } from "./../types/myType";

@Component({
  tag: "app-root",
  styleUrl: "app-root.css",
  shadow: true,
})
export class AppRoot {
  @Event({ eventName: "myTypeEvent" }) showMessage: EventEmitter<MyType>;

  render() {
    return <div> Build Error Test</div>;
  }
}
  1. build the app using "npm run build" - all fine.
  2. Change the import path to something incorrect and build again: the build succeeds.
  3. A second and subsequent builds fail, however.

Code Reproduction URL

https://github.com/petercmuc/build-error

Additional Information

No response

petercmuc avatar May 05 '25 13:05 petercmuc

@petercmuc I can't reproduce this, it fails as expected on the first run:

❯ g clone https://github.com/petercmuc/build-error.git
Cloning into 'build-error'...
remote: Enumerating objects: 28, done.
remote: Counting objects: 100% (28/28), done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 28 (delta 4), reused 21 (delta 4), pack-reused 0 (from 0)
Receiving objects: 100% (28/28), 6.95 KiB | 6.95 MiB/s, done.
Resolving deltas: 100% (4/4), done.
❯ cd build-error/
❯ cursor .
❯ npm i

added 2 packages, and audited 3 packages in 310ms

found 0 vulnerabilities
❯ npm run build

> [email protected] build
> stencil build

[38:22.3]  @stencil/core
[38:22.7]  v4.30.0 🌺
[38:23.1]  build, app, prod mode, started ...
[38:23.1]  transpile started ...
[38:23.4]  transpile finished in 317 ms

[ ERROR ]  TypeScript: src/components.d.ts:18:24
           Cannot find name 'MyType'.

     L17:  interface HTMLAppRootElementEventMap {
     L18:      "myTypeEvent": MyType;
     L19:  }

[ ERROR ]  TypeScript: src/components/app-root/app-root.tsx:6:24
           Cannot find module './../../types/myType' or its corresponding type
           declarations.

      L5:  /** Change the path of the import below to provoke an error */
      L6:  import { MyType } from "./../../types/myType";

[38:23.4]  build failed in 360 ms

christian-bromann avatar May 05 '25 18:05 christian-bromann

@christian-bromann thanks for looking into it. My bad: I had commited the repo with the incorrect path. I have pushed the changes now. Initially the path should be

import { MyType } from "./../types/myType";

petercmuc avatar May 06 '25 14:05 petercmuc

I still observe the same:

❯ g clone https://github.com/petercmuc/build-error.git
Cloning into 'build-error'...
git: 'credential-manager-core' is not a git command. See 'git --help'.
remote: Enumerating objects: 34, done.
remote: Counting objects: 100% (34/34), done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 34 (delta 7), reused 27 (delta 7), pack-reused 0 (from 0)
Receiving objects: 100% (34/34), 7.39 KiB | 3.69 MiB/s, done.
Resolving deltas: 100% (7/7), done.
❯ cd build-error/
❯ npm i

added 2 packages, and audited 3 packages in 508ms

found 0 vulnerabilities
❯ npm run build

> [email protected] build
> stencil build

[11:05.3]  @stencil/core
[11:05.8]  v4.30.0 🌺
[11:06.2]  build, app, prod mode, started ...
[11:06.2]  transpile started ...
[11:06.4]  transpile finished in 194 ms
[11:06.4]  generate lazy + source maps started ...
[11:06.7]  generate lazy + source maps finished in 251 ms
[11:06.7]  copy started ...
[11:06.7]  copy finished (1 file) in 7 ms
[11:06.7]  build finished in 476 ms

🤔

christian-bromann avatar May 06 '25 18:05 christian-bromann

Hey @christian-bromann What you show above is the expected behaviour. You did exactly what I mentioned in step 1. In order to see the problem you now need to change the import to an invalid and build again. This time the build will still succeed although it shouldn't

petercmuc avatar May 07 '25 07:05 petercmuc

I just tried it as well and could reproduce it like @petercmuc described. The incorrect import path leads to a successful build the first time it runs and fails on the second run which would be the correct behavior for both runs.

wittemann avatar May 09 '25 06:05 wittemann

@petercmuc yep I see now, thanks for clarifying! We definitely should check types for every build. Any contributions are appreciated.

christian-bromann avatar May 15 '25 17:05 christian-bromann

I would say whatever the solution, that there should be a flag for this. I have an issue which I think is related #5168

womblep avatar Jun 30 '25 04:06 womblep