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

Getting error in aliased import paths in package #563

Open
bchiong opened this issue Jun 15, 2023 · 4 comments
Open

Getting error in aliased import paths in package #563

bchiong opened this issue Jun 15, 2023 · 4 comments

Comments

@bchiong
Copy link

bchiong commented Jun 15, 2023

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

@bchiong bchiong changed the title Aliased import paths in package get an error Getting error in aliased import paths in package Jun 15, 2023
@emmatown
Copy link
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?

@cdbenj
Copy link

cdbenj commented Jun 15, 2023

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

@emmatown
Copy link
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)

@cdbenj
Copy link

cdbenj commented Jun 15, 2023

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants