Skip to content

Commit af22bb8

Browse files
authored
fix(compiler): don't mistake aliased paths for collections imports (#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
1 parent 9ff643c commit af22bb8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/compiler/transformers/collections/add-external-import.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isString, parsePackageJson } from '@utils';
1+
import { isString, normalizePath, parsePackageJson } from '@utils';
22
import { dirname } from 'path';
33

44
import type * as d from '../../../declarations';
@@ -38,7 +38,9 @@ export const addExternalImport = (
3838
pkgJsonFilePath = realPkgJsonFilePath.path;
3939
}
4040

41-
if (pkgJsonFilePath === config.packageJsonFilePath) {
41+
// realpathSync may return a path that uses Windows path separators ('\').
42+
// normalize it for the purposes of this comparison
43+
if (normalizePath(pkgJsonFilePath) === config.packageJsonFilePath) {
4244
// same package silly!
4345
return;
4446
}

0 commit comments

Comments
 (0)