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

.swcrc loaded via --config-file does not resolve jsc.baseUrl #7800

Closed
kushuh opened this issue Aug 11, 2023 · 10 comments · Fixed by #7801
Closed

.swcrc loaded via --config-file does not resolve jsc.baseUrl #7800

kushuh opened this issue Aug 11, 2023 · 10 comments · Fixed by #7801
Assignees
Labels
Milestone

Comments

@kushuh
Copy link

kushuh commented Aug 11, 2023

Describe the bug

I recently upgraded from "@swc/core": "^1.3.70" to "@swc/core": "^1.3.76", and my configuration does not compile anymore.

Input code

Running the compile command:

npx swc package --config-file .build.swcrc --copy-files -d dist

Config

In my .build.swcrc file.

{
  "jsc": {
    "baseUrl": ".",
    "transform": {
      "react": {
        "runtime": "automatic",
        "importSource": "react"
      }
    },
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "target": "es2022",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    },
    "paths": {
      "@components/stateless": [
        "package/components/stateless"
      ],
      "@components/stateful": [
        "package/components/stateful"
      ],
      "@internal": [
        "internal-components"
      ],
      "@contexts": [
        "package/contexts"
      ],
      "@hooks": [
        "package/hooks"
      ],
      "@lib/backend": [
        "package/lib/backend"
      ],
      "@lib/api": [
        "package/lib/api"
      ],
      "@lib": [
        "package/lib"
      ],
      "@public/*": [
        "package/public/*"
      ],
      "@styles/*": [
        "package/styles/*"
      ]
    }
  },
  "module": {
    "type": "es6",
    "strict": false,
    "lazy": true,
    "noInterop": false
  },
  "minify": false
}

Playground link

No response

Expected behavior

I expect a compilation success (worked well up until at least "@swc/core": "^1.3.70")

Actual behavior

I get this error during compilation:

thread 'thread '<unnamed><unnamed>' panicked at '' panicked at 'base_dir(.) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly.base_dir(.) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly.', ', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_transforms_module-0.173.28/src/path.rs/Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_transforms_module-0.173.28/src/path.rs::104104::1313

Version

"@swc/cli": "^0.1.62" "@swc/core": "^1.3.76"

Additional context

No response

@sambauers
Copy link

sambauers commented Aug 12, 2023

Can confirm this seems to affect @swc/core v1.3.76 and reverting to v1.3.75 removes the issue.

In my project I had not defined baseUrl at all.

UPDATE: I added "baseUrl": ".", to my .swcrc and building with swc on the command line now works with v1.3.76, however testing using @swc/jest still does not work.

My .swcrc config is:

{
  "$schema": "http://json.schemastore.org/swcrc",
  "module": {
    "type": "commonjs"
  },
  "jsc": {
    "baseUrl": ".",
    "parser": {
      "syntax": "typescript",
    },
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  },
  "exclude": [
    "./**/__tests__/*"
  ]
}

My jest.config.js is:

// @ts-check

/**
 * @type {import('@swc/core/types').Options}
 */
const swcConfig = {
  module: {
    type: 'commonjs',
  },
  jsc: {
    baseUrl: '.',
    parser: {
      syntax: 'typescript',
    },
    paths: {
      '@/*': ['./src/*'],
    },
  },
  envName: 'test',
  swcrc: false,
}

/**
 * @type {import('jest').Config}
 */
const jestConfig = {
  transform: {
    '^.+\\.(t|j)sx?$': [
      '@swc/jest',
      // @ts-expect-error swc options are not assignable
      swcConfig,
    ],
  },
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/$1',
  },
  coveragePathIgnorePatterns: ['<rootDir>/jest'],
}

// eslint-disable-next-line no-undef
module.exports = jestConfig

If you need more context, the project I'm trying to upgrade is https://github.com/sambauers/tailwindcss-3d

@kdy1 kdy1 added this to the Planned milestone Aug 12, 2023
@kdy1 kdy1 self-assigned this Aug 12, 2023
@kdy1
Copy link
Member

kdy1 commented Aug 12, 2023

@kushuh If it still occurs, please provide a minimal reproduction .

@kdy1
Copy link
Member

kdy1 commented Aug 12, 2023

swc-project/jest@b17afb5 is about @swc/jest

@sambauers
Copy link

Can confirm this works now for Jest provided I specify a baseUrl, without a baseUrl it fails. Docs say baseUrl is required with paths specified, so I guess that's OK 😄

@kushuh
Copy link
Author

kushuh commented Aug 12, 2023

@kdy1 I was able to confirm the issue is not present on 1.3.75. Here is a minimal reproduction example: https://github.com/kushuh/bug-swc-base-url

@kushuh
Copy link
Author

kushuh commented Aug 12, 2023

I was also able to reproduce the issue without using jest 🤔

@kdy1
Copy link
Member

kdy1 commented Aug 12, 2023

Ah, npx swc invokes the native CLI... I only patched js API 🤣
I'll fix it and publish a new version later today.

@kdy1 kdy1 reopened this Aug 12, 2023
@kdy1 kdy1 changed the title Cannot use relative jsc.baseUrl anymore in .swcrc config Native CLI does not support non-absolute jsc.baseUrl Aug 12, 2023
@kdy1
Copy link
Member

kdy1 commented Aug 12, 2023

Oh the problem was --config-file

@kdy1 kdy1 changed the title Native CLI does not support non-absolute jsc.baseUrl .swcrc loaded via --config-file does not resolve jsc.baseUrl Aug 12, 2023
@kdy1
Copy link
Member

kdy1 commented Aug 12, 2023

Postponing to working hours as it's about --config-file, not default option

@swc-bot
Copy link
Collaborator

swc-bot commented Sep 15, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Sep 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

4 participants