-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Cannot find module 'webpack/lib/TemplatedPathPlugin' #10565
Comments
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
看了一下,没找到很好的解决方案,因为这个 babel 插件用了深层导入 webpack 内部的东西: // https://github.com/birdofpreyru/babel-plugin-react-css-modules/blob/master/src/getLocalIdent.js
import TemplatedPathPlugin from 'webpack/lib/TemplatedPathPlugin';
import createHash from 'webpack/lib/util/createHash'; 而 webpack 没有公开这两个方法,同时 umi 不提供非公开方法的 webpack 导出,所以就找不到。 目前想到的一个比较 hack 的解决方法是: pnpm add -D webpack // .umirc.ts
import path from 'path'
function webpackDeepPathImportWorkaround() {
const webpackPath = path.join(__dirname, './node_modules/webpack/lib')
const mod = require('module')
const resolveFilename = mod._resolveFilename
const hookPropertyMap = new Map()
hookPropertyMap.set(
'webpack/lib/TemplatedPathPlugin',
path.join(webpackPath, './TemplatedPathPlugin.js')
)
hookPropertyMap.set(
'webpack/lib/util/createHash',
path.join(webpackPath, './util/createHash.js')
)
mod._resolveFilename = function (
request: string,
parent: any,
isMain: boolean,
options: any
) {
const hookResolved = hookPropertyMap.get(request)
if (hookResolved) request = hookResolved
return resolveFilename.call(mod, request, parent, isMain, options)
}
}
webpackDeepPathImportWorkaround()
// 在这行导入上面添加这个函数 ↑
const {
getLocalIdent,
generateScopedNameFactory,
} = require('@dr.pogodin/babel-plugin-react-css-modules/utils') |
@fz6m 非常感谢!!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What happens?
我在集成 @dr.pogodin/babel-plugin-react-css-modules 这个babel插件的时候,编译会报错
我在bundler-webpack代码中似乎没找到TemplatedPathPlugin。
https://github.com/umijs/umi/blob/master/packages/bundler-webpack/package.json
是预打包的webpack有什么没依赖进来吗?
这是我和库作者的对话
birdofpreyru/babel-plugin-react-css-modules#37
Mini Showcase Repository(REQUIRED)
How To Reproduce
Context
"umi": "^4.0.52"
node -v v16.19.0
mac
The text was updated successfully, but these errors were encountered: