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

@unocss/webpack 开启 watch 时报错 #3613

Open
4 tasks done
StephenPCG opened this issue Mar 12, 2024 · 2 comments
Open
4 tasks done

@unocss/webpack 开启 watch 时报错 #3613

StephenPCG opened this issue Mar 12, 2024 · 2 comments

Comments

@StephenPCG
Copy link

UnoCSS version

0.58.5

Describe the bug

webpack 中的配置如下:

import UnoCSS from '@unocss/webpack';

...

memo.plugin('unocss').use(UnoCSS({
    configFile: './uno.config.ts',
    watch: true,
}));

启动 webpack 时:

node:internal/modules/esm/utils:213
  throw new ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING();
        ^

TypeError: A dynamic import callback was not specified.
    at importModuleDynamicallyCallback (node:internal/modules/esm/utils:213:9)
    at setupContentExtractor (/.../node_modules/@unocss/webpack/dist/index.cjs:255:25)
    at async Promise.all (index 0)
    at async flushTasks (/.../node_modules/@unocss/webpack/dist/index.cjs:133:5)
    at async Timeout.updateModules [as _onTimeout] (/.../node_modules/@unocss/webpack/dist/index.cjs:411:7) {
  code: 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING'
}

Reproduction

查看 node_modules/@unocss/webpack/dist/index.cjs ,报错的是这一行:

const { watch } = await import('chokidar');

手动改为 const { watch } = require('chokidar'); 即可正常运行。

System Info

No response

Validations

@StephenPCG
Copy link
Author

BTW,我这里并不是直接使用的 webpack,而是在 umijs/father 中使用,fatherrc.ts 文件这样配置:

export default defineConfig({
    umd: {
        chainWebpack: (memo) => {
            ...
            memo.plugin('unocss').use(UnoCSS({
            configFile: './uno.config.ts',
            watch: true,
            }));
            ...
            return memo
        }
    }
})

不清楚这个问题是 father 的还是哪里的。

我对 js 生态不太熟悉,平时主要写后端代码。提的问题如果太 naive 还请见谅😂

@StephenPCG
Copy link
Author

还有一个额外的问题(不是 bug):

      const watcher = watch(files, {
        ignorePermissionErrors: true,
        ignored,
        cwd: root,
        ignoreInitial: true,
      })

这里的 watch(files) 能否改为 watch(content.filesystem),因为 files 已经被展开了,后续有新增的文件不会被发现,如果直接把 content.filesystem 传递给 watch,则新增的文件也能被发现。不知道设计上是否有什么特殊的考虑?

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

1 participant