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

SWC error: jsc.baseUrl must be absolute #41

Closed
maslennikov opened this issue Aug 23, 2023 · 3 comments · Fixed by #44
Closed

SWC error: jsc.baseUrl must be absolute #41

maslennikov opened this issue Aug 23, 2023 · 3 comments · Fixed by #44

Comments

@maslennikov
Copy link

maslennikov commented Aug 23, 2023

Problem
With the recent update(issues here and here), swc doesn't accept relative baseUrl anymore. When rollup plugin reads tsconfig.json, it passes baseUrl in whatever format is there, and normally, it is something like . or ./src. It leads to errors:

[!] (plugin swc) Error: failed to handle: base_dir(./) must be absolute. Please ensure that jsc.baseUrl is specified correctly. This cannot be deduced by SWC itself because SWC is a transpiler and it does not try to resolve project details. In other works, SWC does not know which directory should be used as a base directory. It can be deduced if .swcrc is used, but if not, there are many candidates. e.g. the directory containing package.json, or the current working directory. Because of that, the caller (typically the developer of the JavaScript package) should specify it. If you see this error, please report an issue to the package author.

Suggested solution
If tsconfig file found, resolve baseUrl as absolute path (value from its compilerOptions.baseUrl field resolved against absolute path of the given tsconfig file)

@maslennikov
Copy link
Author

Right now I solved this with manual baseUrl resolution in base config file shared across monorepo packages:

import fs from 'node:fs'
import path from 'node:path'
import json5 from 'json5'

// HACK https://github.com/SukkaW/rollup-plugin-swc/issues/41
const tsconfig = json5.parse(fs.readFileSync(TSCONFIG_PATH))
const baseUrl = path.resolve(tsconfig.compilerOptions.baseUrl)

export default {
  // rest skipped
  plugins: [
    swc({
      tsconfig: TSCONFIG_PATH,
      jsc: {
        baseUrl,
      },
    }),
  ],
}

@SukkaW
Copy link
Owner

SukkaW commented Aug 23, 2023

Thanks for reporting this!

However, rollup-plugin-swc3 also supports extends in the tsconfig.json as well. So keeping the previous behavior might not be that easy.

@theIYD
Copy link

theIYD commented Nov 16, 2023

@SukkaW I am using rollup-plugin-dts to generate the declaration files. With this plugin, the above error is thrown.

plugin version: 0.10.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

Successfully merging a pull request may close this issue.

3 participants