Skip to content

Getting error in aliased import paths in package #563

Open

Description

@bchiong

Hi,

Is there a way to resolve this error when using aliased import paths?

"{import}" is imported by "{path}" but the package is not specified in dependencies or peerDependencies

import { component } from '#path/to/component';

I have an import statement which get resolved through tsconfig and eslint but when I run preconstruct build I get an error.

Thank you

Activity

  1. changed the title [-]Aliased import paths in package get an error[/-] [+]Getting error in aliased import paths in package[/+] on Jun 15, 2023
  2. emmatown commented on Jun 15, 2023

    @emmatown
    Member

    Is this with the package.json imports field or the paths option in a tsconfig? Preconstruct (intentionally) doesn't resolve with paths in tsconfigs but the package.json imports field should work. If you're using the package.json imports field, could you provide a more complete reproduction?

  3. cdbenj commented on Jun 15, 2023

    @cdbenj

    Thanks @emmatown

    I only did it on tsconfigs. But, I tried it on the imports field on package.json just now after you mentioned it. Unfortunately, it's still giving me an error.

    Here's a reproduction of the package.json

    This is added on the workspace level, and not on the root.

    {
      "name": "@workspace/package",
      "version": "1.0.0",
      "main": "dist/package.cjs.js",
      "module": "dist/package.esm.js",
      "sideEffects": false,
      "license": "MIT",
      "imports": {
        "#package/path/to/component/*": "./src/path/to/component/*"
      },
      "devDependencies": {
      ...
      },
      "dependencies": {
       ...
      },
      "peerDependencies": {
       ...
      }
    }
    
    

    node version: 19.2.0

  4. emmatown commented on Jun 15, 2023

    @emmatown
    Member

    The imports field requires extensions so for example you need to import e.g. #package/path/to/component/something.ts or include the extension in the pattern like e.g.

    "imports": {
      "#package/path/to/component/*": "./src/path/to/component/*.ts"
    },

    (Note this requirement isn't a Preconstruct-specific thing, this is just how the imports field works in Node itself and a bunch of other tools that support Node-style module resolution such as e.g. TypeScript with the "moduleResolution": "nodenext"/"bundler" compiler option)

  5. cdbenj commented on Jun 15, 2023

    @cdbenj

    I see. Let me try it then. Thanks for you guidance 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions