带有Ant设计的Snowpack:无法解析导入的“ antd”

问题描述

我想将Ant Design与Snowpack一起使用。我遵循And Design文档并安装了antd,但是无论何时运行我的应用程序,都无法解决依赖关系。

我收到以下错误消息:

[snowpack] Import "antd" could not be resolved.
If this is a new package,re-run Snowpack with the --reload flag to rebuild.
If Snowpack is having trouble detecting the import,add "install": ["antd"] to your Snowpack config file.

我的App.tsx:

import React from 'react';
import './App.css';
import { Button } from 'antd';

function App(): JSX.Element {
    return (
        <div className="App">
            <Button type="primary">Button</Button>
        </div>
    );
}

export default App;

我的package.json依赖项:

"dependencies": {
    "antd": "^4.6.2","axios": "^0.20.0","postcss": "^7.0.32","react": "^16.13.1","react-dom": "^16.13.1","react-hook-form": "^6.7.0","tailwindcss": "^1.7.6"
  },"devDependencies": {
    "@snowpack/app-scripts-react": "^1.10.0","@testing-library/jest-dom": "^5.5.0","@testing-library/react": "^10.0.3","@types/react": "^16.9.35","@types/react-dom": "^16.9.8","@types/snowpack-env": "^2.3.0","@typescript-eslint/eslint-plugin": "^4.0.1","@typescript-eslint/parser": "^4.0.1","eslint": "^7.8.0","eslint-config-prettier": "^6.11.0","eslint-plugin-prettier": "^3.1.4","eslint-plugin-react": "^7.20.6","eslint-plugin-react-hooks": "^4.1.0","jest": "^26.2.2","postcss-cli": "^7.1.2","prettier": "^2.0.5","snowpack": "^2.9.0","typescript": "^3.9.7"
  }

我想念什么吗?

解决方法

确保已安装antd。在snowpack.config.json中尝试:

module.exports = {
  mount: {
    public: '/',src: '/_dist_',}
  installOptions: {
    namedExports: ['antd'],},};

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...