我正在使用antdesign,请做出反应。我要实现深色主题。我通过使用config-overrides.js和custom-cra自定义主题。这是代码
const { override, fixBabelImports, addLessLoader } = require('customize-cra');
const darkTheme = require('@ant-design/dark-theme');
module.exports = override(
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: true,
}),
addLessLoader({
javascriptEnabled: true,
modifyVars: { '@primary-color': '#1DA57A' },
}),
);
如果我尝试在不使用darkTheme的情况下运行它,那么它将运行完美。但是,如果我添加这一行,则纱线启动时会出现以下错误
yarn start
yarn run v1.21.1
$ react-app-rewired start
internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module 'antd/dist/dark-theme'
Require stack:
- D:\Documents\Projects\WebDevelopment\setup-ant-design\node_modules\@ant-design\dark-theme\index.js
- D:\Documents\Projects\WebDevelopment\setup-ant-design\config-overrides.js
- D:\Documents\Projects\WebDevelopment\setup-ant-design\node_modules\react-app-rewired\config-overrides.js
- D:\Documents\Projects\WebDevelopment\setup-ant-design\node_modules\react-app-rewired\scripts\start.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (D:\Documents\Projects\WebDevelopment\setup-ant-design\node_modules\@ant-design\dark-theme\index.js:18:36)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'D:\\Documents\\Projects\\WebDevelopment\\setup-ant-design\\node_modules\\@ant-design\\dark-theme\\index.js',
'D:\\Documents\\Projects\\WebDevelopment\\setup-ant-design\\config-overrides.js',
'D:\\Documents\\Projects\\WebDevelopment\\setup-ant-design\\node_modules\\react-app-rewired\\config-overrides.js',
'D:\\Documents\\Projects\\WebDevelopment\\setup-ant-design\\node_modules\\react-app-rewired\\scripts\\start.js'
]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.