Skip to content

alias plugin: relative import replacements not working properly #1518

@TheDanielMoli

Description

@TheDanielMoli

Hi! We have the following folder structure:

  • project_folder/src contains TypeScript source code
  • project_folder/ts_config.json defines "baseUrl": "src" and paths "~/*": ["./*"]
  • project_folder/rollup.config.mjs uses the following configuration:
plugins: [
      image(),
      json(),
      peerDepsExternal(),
      resolve(),
      commonjs(),
      typescript({ tsconfig: './tsconfig.json' }),
      terser(),
      alias({
        entries: {
          '~': path.resolve(projectRootDir, './src'),
        },
      }),
      copy({
        targets: [{ src: 'src/assets/fonts/*', dest: 'fonts' }],
      }),
      copy({
        targets: [{ src: 'src/assets/icons/*.svg', dest: ['dist/cjs/assets/icons', 'dist/esm/assets/icons'] }],
      }),
],

and

    plugins: [
      image(),
      alias({
        entries: {
          '~': path.resolve(projectRootDir, './src'),
        },
      }),
      dts(),
    ],
  • project_folder/src/components contains all our TypeScript components

Each TypeScript component is exported from components/index.ts.

Now, where is the problem?

There seems to be a problem when a sibling file imports code from another sibling through an absolute import.

Given this folder structure:

src
  components
    Box
      Box.tsx
      index.ts
    FlexLayout
      FlexLayout.tsx
      index.ts

When importing for example Box from Box.tsx into FlexLayout.tsx via an absolute import import { BoxProps } from '~/components' will cause problems, while importing directly will not import { BoxProps } from '../Box'. We have no idea why. Also, we are able to both run the project and render the component, but rollup won't work.

This problem does not affect non-sibling file imports.

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions