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

Error: Dynamic require of "path" is not supported #30

Closed
bestickley opened this issue Jul 21, 2022 · 5 comments
Closed

Error: Dynamic require of "path" is not supported #30

bestickley opened this issue Jul 21, 2022 · 5 comments
Labels

Comments

@bestickley
Copy link

Hello, thanks so much for creating this library! Fills a big gap within Vite/Vitest community.
I'm getting this error:

Error: Dynamic require of "path" is not supported
    at file:///Users/stickb/Code/niwc-pac/cosmos/node_modules/.pnpm/[email protected]_g6o72fkdx62msvhc7bd7opzgc4/node_modules/unplugin-swc/dist/index.mjs:29:9
    at node_modules/.pnpm/[email protected]/node_modules/picomatch/lib/picomatch.js (file:///Users/stickb/Code/niwc-pac/cosmos/node_modules/.pnpm/[email protected]_g6o72fkdx62msvhc7bd7opzgc4/node_modules/unplugin-swc/dist/index.mjs:1377:17)
    at __require2 (file:///Users/stickb/Code/niwc-pac/cosmos/node_modules/.pnpm/[email protected]_g6o72fkdx62msvhc7bd7opzgc4/node_modules/unplugin-swc/dist/index.mjs:47:50)
    at node_modules/.pnpm/[email protected]/node_modules/picomatch/index.js (file:///Users/stickb/Code/niwc-pac/cosmos/node_modules/.pnpm/[email protected]_g6o72fkdx62msvhc7bd7opzgc4/node_modules/unplugin-swc/dist/index.mjs:1522:22)
    at __require2 (file:///Users/stickb/Code/niwc-pac/cosmos/node_modules/.pnpm/[email protected]_g6o72fkdx62msvhc7bd7opzgc4/node_modules/unplugin-swc/dist/index.mjs:47:50)
    at file:///Users/stickb/Code/niwc-pac/cosmos/node_modules/.pnpm/[email protected]_g6o72fkdx62msvhc7bd7opzgc4/node_modules/unplugin-swc/dist/index.mjs:1583:32
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)

Any ideas what I'm doing wrong?

vite.config.ts

import { defineConfig } from "vite";
import swc from "unplugin-swc";

export default defineConfig({
  plugins: [swc.vite(), swc.rollup()],
});

tsconfig.json

{
  "compilerOptions": {
"target": "esnext",
    "module": "ESNext",
    "moduleResolution": "node",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "strictPropertyInitialization": false,
    "noEmit": true,
  },
  "ts-node": {
    "swc": true,
    "esm": true
  },
}
@StasPotapenko
Copy link

removing "type":"module" in package.json, solved the issue for me..

@bestickley
Copy link
Author

@StasPotapenko, appreciate the tip. If anyone knows any workarounds to use this with an ESM package that would be much appreciated.

@Refzlund
Copy link

Refzlund commented Sep 22, 2022

I build the project (unplugin-swc) using tsc and made it into a module. This resolved this error🕺

https://github.com/Refzlund/unplugin-swc-module

@tianyingchun
Copy link

i simply change something to fit my project type:module, nodenext https://github.com/tianyingchun/unplugin-swc-esm

it works fine, waiting latest unplugin-swc release

@github-actions
Copy link

🎉 This issue has been resolved in version 1.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants