Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WINDOWS path aliases cause: [ ERROR ] Component Tag Name "my-component" Must Be Unique #2319

Closed
mmakrzem opened this issue Mar 27, 2020 · 17 comments
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil

Comments

@mmakrzem
Copy link

mmakrzem commented Mar 27, 2020

Stencil version:

I'm submitting a:

[X ] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:
I am seeing the error:

[ ERROR ] Component Tag Name "my-component" Must Be Unique

This error has started showing up since updated my code from stencil v1.9.2. I tried v1.10.0, v.1.10.1, v1.10.2, v1.10.3, v.1.11.0, v1.11.1, v1.11.2 All versions after 1.9 seem to exhibit the same problem.

I have taken the starter project from stencil and updated it to contain one alias pointing to the utils directory. I also created a second component in the sample project. Now I'm able to see this error message in the starter project.

I am running this on Windows 10.

Expected behavior:
Expecting no error so that I'm able to run the code

Steps to reproduce:
grab the source code from here: https://github.com/mmakrzem/stencil1-11-error

execute the following commands in order
run npm install
npm run start //it runs fine
npm run test //it runs fine
npm run start //now getting an error messages

[ ERROR ]  Component Tag Name "my-component" Must Be Unique
           Please update the components so "my-component" is only used once:
           ./src/components/my-component/my-component.tsx ./dist/collection/components/my-component/my-component.js

[ ERROR ]  Component Tag Name "my-component2" Must Be Unique
           Please update the components so "my-component2" is only used once:
           ./dist/collection/components/my-component2/my-component2.js ./src/components/my-component2/my-component2.tsx

Here is my Windows console output:

PS D:\broken> npm i

> [email protected] install D:\broken\node_modules\puppeteer
> node install.js

Downloading Chromium r674921 - 141.6 Mb [====================] 100% 0.0s
Chromium downloaded to D:\broken\node_modules\puppeteer\.local-chromium\win64-674921
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 699 packages from 438 contributors and audited 1784142 packages in 90.414s

17 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

PS D:\broken> npm run start                                                       
> [email protected] start D:\broken
> stencil build --dev --watch --serve

[21:49.9]  @stencil/core v1.11.2
[21:54.2]  build, st1112, dev mode, started ...
[21:54.3]  transpile started ...
[22:02.6]  transpile finished in 8.39 s
[22:02.7]  copy started ...
[22:02.7]  generate lazy started ...
[22:02.7]  copy finished (0 files) in 71 ms
[22:03.6]  generate lazy finished in 960 ms
[22:03.7]  build finished, watching for changes... in 9.45 s

Terminate batch job (Y/N)? y
PS D:\broken>
PS D:\broken> npm run test

> [email protected] test D:\broken
> stencil test --spec --e2e

[22:14.7]  @stencil/core v1.11.2
[22:14.9]  testing e2e and spec files
[22:18.4]  build, st1112, dev mode, started ...
[22:18.8]  transpile started ...
[22:26.9]  transpile finished in 8.07 s
[22:26.9]  copy started ...
[22:26.9]  generate lazy started ...
[22:27.4]  copy finished (0 files) in 498 ms
[22:31.2]  generate lazy finished in 4.31 s
[22:31.3]  build finished in 12.92 s

[22:31.4]  jest args: --e2e --spec --max-workers=8
 PASS  src/utils/utils.spec.ts (5.521s)
 PASS  src/components/my-component/my-component.e2e.ts (7.288s)
 PASS  src/components/my-component2/my-component2.e2e.ts (7.297s)

Test Suites: 3 passed, 3 total
Tests:       8 passed, 8 total
Snapshots:   0 total
Time:        9.733s
Ran all test suites.

PS D:\broken> npm run start                                                       
> [email protected] start D:\broken
> stencil build --dev --watch --serve

[23:01.3]  @stencil/core v1.11.2
[23:05.2]  build, st1112, dev mode, started ...
[23:05.2]  transpile started ...
[23:12.8]  transpile finished in 7.53 s

[ ERROR ]  Component Tag Name "my-component" Must Be Unique
           Please update the components so "my-component" is only used once:
           ./src/components/my-component/my-component.tsx ./dist/collection/components/my-component/my-component.js

[ ERROR ]  Component Tag Name "my-component2" Must Be Unique
           Please update the components so "my-component2" is only used once:
           ./dist/collection/components/my-component2/my-component2.js ./src/components/my-component2/my-component2.tsx

[23:12.8]  build failed, watching for changes... in 7.60 s

Terminate batch job (Y/N)? y
PS D:\broken>
@ionitron-bot ionitron-bot bot added the triage label Mar 27, 2020
@mmakrzem
Copy link
Author

Some additional information. A guy on Slack attempted to reproduce the problem on his macOS computer but was unable to. So this might be a Windows specific bug.

@mmakrzem
Copy link
Author

mmakrzem commented Mar 27, 2020

After further investigation, I was able to track down the cause of the problem. Stencil seems to be handling path aliases incorrectly. in v1.9 my project required a devDependency for "rollup-plugin-typescript-paths" because in my stencil.config file I had to use:

plugins: [
    typescriptPaths()
  ],

In v1.10 and v1.11 this code would not even compile. On Slack I was told to remove this since typescriptPaths is now handled under the hood by Stencil.

So to replicate the problem with a fresh stencil project do the following.

npm init stencil

edit the package.json file to use stencil v1.11.2

update my-component.tsx to have an aliased path to utils:
import { format } from '@myUtils';

edit the tsconfig.json file by adding:

"baseUrl": "./",
    "paths": {
      "@myUtils": ["src/utils"]
    },

edit the stencil.config.ts to also include:

testing: {
    moduleFileExtensions: [
      'ts',
      'tsx',
      'json',
      'js',
      'jsx'
    ],
    moduleNameMapper: {
      '^@myUtils$': 'src/utils'
    },
    testRegex: '^(?!.*test\/.*)(?!(.*\\.(util|extraneous|testReport|base)\\.e2e\\.ts$)).*\\.(spec|e2e)\\.(ts?|tsx?)$',
  }

lastly add an index.ts file into the src/utils directory. This file should contain:
export * from './utils'

Now run:

npm run start
npm run test
npm run start

I get the error :
[ ERROR ] Component Tag Name "my-component" Must Be Unique
Please update the components so "my-component" is only used once:
./src/components/my-component/my-component.tsx ./dist/collection/components/my-component/my-component.js

@mmakrzem mmakrzem changed the title [ ERROR ] Component Tag Name "my-component" Must Be Unique path aliases cause: [ ERROR ] Component Tag Name "my-component" Must Be Unique Mar 27, 2020
@manucorporat
Copy link
Contributor

Can you share your tsconfig.json?

@mmakrzem
Copy link
Author

@manucorporat you can see the tsconfig.json file along with all the source code in my github https://github.com/mmakrzem/stencil1-11-error/blob/master/tsconfig.json

@mmakrzem
Copy link
Author

@manucorporat This is what the tsconfig.json file looks like after modifying the fresh Stencil project

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "allowUnreachableCode": false,
    "declaration": false,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2017"
    ],
    "moduleResolution": "node",
    "module": "esnext",
    "target": "es2017",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "jsx": "react",
    "jsxFactory": "h",
	"baseUrl": "./",                       
    "paths": {
      "@myUtils": ["src/utils"]
    },
  },
  "include": [
    "src",
    "types/jsx.d.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

@mmakrzem
Copy link
Author

an additional piece of information. It seems like executing npm run test is what causing things to go bad.

I can start fresh, do npm run start multiple times with no problems. But as soon as I run npm run test, something changes and I can no longer run npm run start, nor can I run npm run test a second time without getting that error about component tag name must be unique.

@mmakrzem
Copy link
Author

Still a problem with Stencil v1.14.0

@juliovedovatto
Copy link

Still a problem with Stencil v1.17.2 on Windows

If I remove ./dist dir before build, it works as expected.

MacOS and Linux build process runs perfectly.

@mmakrzem mmakrzem changed the title path aliases cause: [ ERROR ] Component Tag Name "my-component" Must Be Unique WINDOWS path aliases cause: [ ERROR ] Component Tag Name "my-component" Must Be Unique Jul 31, 2020
@sean-perkins
Copy link
Contributor

Seeing this issue as well on one of our interns machines that is a Windows OS. Even with adding dist to the excludes portion of the tsconfig, it still compiles that directory (only on Windows).

@ch3rub1
Copy link

ch3rub1 commented Oct 29, 2020

A little bump on this since I've just encounter the issue when trying to configure path aliases on a Windows 10 environment 😄

@yigityuce
Copy link
Contributor

Is there any update on this?

@boblelot
Copy link

boblelot commented Mar 6, 2021

Also encounter this error today on Windows, issue was related to an import path.
Will produce the error: import { function } from 'src/utils/json.utils';
This works: import { function } from '../../../utils/json.utils';

@rohitgarg025
Copy link

Still a problem with Stencil v1.17.2 on Windows

If I remove ./dist dir before build, it works as expected.

MacOS and Linux build process runs perfectly.

This works!

@anderssonjohan
Copy link

Also encounter this error today on Windows, issue was related to an import path. Will produce the error: import { function } from 'src/utils/json.utils'; This works: import { function } from '../../../utils/json.utils';

This is the reason why one of our component repositories started to fail.

I believe the reason for the project relative import was due to me using code actions such as alt+enter to add the imports when authoring the code in VSCode. This worked fine for months on my mac and on the build servers until a developer using a Windows box tried to build the repo.

Searching through the repo for from 'src/ and updated to file relative paths fixed the problem on Windows boxes. 🎉

lucafoscili added a commit to smeup/ketchup that referenced this issue Dec 24, 2021
@rwaskiewicz rwaskiewicz added Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team and removed Feature: Bundling labels Mar 25, 2022
@borisdiakur
Copy link

borisdiakur commented Feb 16, 2023

I had the same problem on OS X today. Could resolve it by replacing all absolute imports with relative ones in my project:

Instead of:

import { getClassNames } from 'src/lib/utils/getClassNames'

I now use:

import { getClassNames } from '../../utils/getClassNames'

This seams to fix an issue where all of a sudden modules get imported from a wrong location, presumably the src folder.

@liamdebeasi
Copy link
Contributor

Here is a reproduction of the issue using the latest version of Stencil: https://github.com/liamdebeasi/blank-stencil-repro/tree/windows-name-alias

Steps to reproduce:

  1. Clone repo (make sure you are on the windows-name-alias branch)
  2. Run npm install to install dependencies
  3. Run npm run build
  4. Run npm run start. Observe that the reported error appears.

rwaskiewicz added a commit that referenced this issue Apr 3, 2024
this commit fixes an issue where stencil builds that followed a
successful build  would result in the following error:
```
[ ERROR ]  Component Tag Name "my-component" Must Be Unique
           Please update the components so "my-component" is only used once:
           ./src/components/my-component/my-component.tsx ./dist/collection/components/my-component/my-component.js
```

this issue manifested on windows machines when building the ionic
framework after a successful build. we were able reproduce this with a
minimal stencil-component-starter that included the following in its
`tsconfig.json`:
```json
{
    paths: {
        "@utils/*": ["src/utils/*"]
    }
}
```

the import alias would be used as such:
```ts
// src/utils/helpers.ts
export const foo = () => console.log('hello');

// src/utils/other-file.ts
import { foo } from '@utils/helpers';

export const bar = () => { foo(); }
```

where in the example above, `helpers.ts` is imported by `other-file.ts`,
and resolved via the `@utils/*` path alias. note that neither of these
files needed to be imported into a stencil component in order for the
error to be replicated - they just need to sit in the `src` directory of
the project.

the reason the project would fail to compile is that the first build
would create a `dist/collections` directory, as the `dist` output target
would synthetically inject (automatically decide the project should
also have) the collections output target in its output. on the second
compilation, stencil would attempt to reconcile `@utils/helpers` as a
collections output, and inadvertantly pull in `dist/collections/*` into
the build context. this caused previously compiled versions of any
components to be recommpiled.

when stencil tried to check for html tag uniqueness, it would detect
multiples components with the same tag, with the previously mentioned
 error:
```
[ ERROR ]  Component Tag Name "my-component" Must Be Unique
           Please update the components so "my-component" is only used once:
           ./src/components/my-component/my-component.tsx ./dist/collection/components/my-component/my-component.js
```

Fixes: #2319
STENCIL-1252
rwaskiewicz added a commit that referenced this issue Apr 3, 2024
this commit fixes an issue where stencil builds that followed a
successful build  would result in the following error:
```
[ ERROR ]  Component Tag Name "my-component" Must Be Unique
           Please update the components so "my-component" is only used once:
           ./src/components/my-component/my-component.tsx ./dist/collection/components/my-component/my-component.js
```

this issue manifested on windows machines when building the ionic
framework after a successful build. we were able reproduce this with a
minimal stencil-component-starter that included the following in its
`tsconfig.json`:
```json
{
    paths: {
        "@utils/*": ["src/utils/*"]
    }
}
```

the import alias would be used as such:
```ts
// src/utils/helpers.ts
export const foo = () => console.log('hello');

// src/utils/other-file.ts
import { foo } from '@utils/helpers';

export const bar = () => { foo(); }
```

where in the example above, `helpers.ts` is imported by `other-file.ts`,
and resolved via the `@utils/*` path alias. note that neither of these
files needed to be imported into a stencil component in order for the
error to be replicated - they just need to sit in the `src` directory of
the project.

the reason the project would fail to compile is that the first build
would create a `dist/collections` directory, as the `dist` output target
would synthetically inject (automatically decide the project should
also have) the collections output target in its output. on the second
compilation, stencil would attempt to reconcile `@utils/helpers` as a
collections output, and inadvertantly pull in `dist/collections/*` into
the build context. this caused previously compiled versions of any
components to be recommpiled.

when stencil tried to check for html tag uniqueness, it would detect
multiples components with the same tag, with the previously mentioned
 error:
```
[ ERROR ]  Component Tag Name "my-component" Must Be Unique
           Please update the components so "my-component" is only used once:
           ./src/components/my-component/my-component.tsx ./dist/collection/components/my-component/my-component.js
```

Fixes: #2319
STENCIL-1252
github-merge-queue bot pushed a commit that referenced this issue Apr 4, 2024
…5620)

this commit fixes an issue where stencil builds that followed a
successful build  would result in the following error:
```
[ ERROR ]  Component Tag Name "my-component" Must Be Unique
           Please update the components so "my-component" is only used once:
           ./src/components/my-component/my-component.tsx ./dist/collection/components/my-component/my-component.js
```

this issue manifested on windows machines when building the ionic
framework after a successful build. we were able reproduce this with a
minimal stencil-component-starter that included the following in its
`tsconfig.json`:
```json
{
    paths: {
        "@utils/*": ["src/utils/*"]
    }
}
```

the import alias would be used as such:
```ts
// src/utils/helpers.ts
export const foo = () => console.log('hello');

// src/utils/other-file.ts
import { foo } from '@utils/helpers';

export const bar = () => { foo(); }
```

where in the example above, `helpers.ts` is imported by `other-file.ts`,
and resolved via the `@utils/*` path alias. note that neither of these
files needed to be imported into a stencil component in order for the
error to be replicated - they just need to sit in the `src` directory of
the project.

the reason the project would fail to compile is that the first build
would create a `dist/collections` directory, as the `dist` output target
would synthetically inject (automatically decide the project should
also have) the collections output target in its output. on the second
compilation, stencil would attempt to reconcile `@utils/helpers` as a
collections output, and inadvertantly pull in `dist/collections/*` into
the build context. this caused previously compiled versions of any
components to be recommpiled.

when stencil tried to check for html tag uniqueness, it would detect
multiples components with the same tag, with the previously mentioned
 error:
```
[ ERROR ]  Component Tag Name "my-component" Must Be Unique
           Please update the components so "my-component" is only used once:
           ./src/components/my-component/my-component.tsx ./dist/collection/components/my-component/my-component.js
```

Fixes: #2319
STENCIL-1252
@rwaskiewicz rwaskiewicz added Bug: Validated This PR or Issue is verified to be a bug within Stencil and removed Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team labels Apr 4, 2024
@rwaskiewicz
Copy link
Member

The fix for this issue has been released as a part of today's Stencil v4.14.1 release. I'm going to close this issue as a result. If you're still running into this issue after upgrading to v4.14.1, please feel free to open a new issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil
Projects
None yet
Development

No branches or pull requests