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

"" Is imported by "", but could not be resolved – treating it as an external dependency. #394

Open
ElYaiko opened this issue May 7, 2024 · 2 comments

Comments

@ElYaiko
Copy link

ElYaiko commented May 7, 2024

Environment

2.0.0
Node 19

Reproduction

Describe the bug

When using unbuild I get:

"~~/utils/misc" is imported by "src/utils/intl.ts", but could not be resolved – treating it as an external dependency.

But it is defined in the tsconfig.json:

{
  "compilerOptions": {
    "lib": ["ESNext"],
    "module": "esnext",
    "target": "esnext",
    "rootDir": "./",
    "baseUrl": "./src",
    "outDir": "./dist",
    "moduleResolution": "bundler",
    "moduleDetection": "force",
    "allowImportingTsExtensions": true,
    "noEmit": true,
    // "composite": true,
    "strict": true,
    "downlevelIteration": true,
    "skipLibCheck": true,
    "jsx": "react-jsx",
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "noUnusedLocals": false,
    "allowJs": true,
    "paths": {
      "~~": ["."],
      "~~/*": ["./*"]
    },
    "types": [
      "bun-types" // add Bun global
    ]
  },
  // "include": [
  //   "src"
  // ],
  "exclude": [
    "dist"
  ]

Additional context

No response

Logs

No response

Copy link
Member

unbuild does not use typescript to build your app. It uses rollup, so setting a path there doesn't tell rollup how to resolve it.

@s3xysteak
Copy link
Contributor

s3xysteak commented Jul 18, 2024

Like what Daniel said you should tell rollup how to resolve alias.

// build.config.ts
import { URL, fileURLToPath } from 'node:url';
import { defineBuildConfig } from 'unbuild';

export default defineBuildConfig({
  alias: {
    '~~': fileURLToPath(new URL('./', import.meta.url)),
  },
  rollup: {
    inlineDependencies: true,
  },
});

Btw you still need inlineDependencies: true to use alias in unbuild, which was a bug fixed in #384 and released in v3.0.0-rc.2.

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