首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >找不到模块‘classname’的声明文件

找不到模块‘classname’的声明文件
EN

Stack Overflow用户
提问于 2021-09-09 19:06:27
回答 1查看 1.1K关注 0票数 1

当我尝试import cn from 'classnames'时,我看到这个错误:

代码语言:javascript
运行
复制
Could not find a declaration file for module 'classnames'. 'C:/Users/Demian/Desktop/udemy/react+next/top-app/node_modules/classnames/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/classnames` if it exists or add a new declaration (.d.ts) file containing `declare module 'classnames';`

npm i --save-dev @types/classnames和使用declare module 'classnames';从错误日志创建.d.ts文件无济于事

其他变体,如npm install -D @types/module-name或来自StackOverflow的npm install @types/module-name也没有太大帮助。在它们之后,我看到了另一个错误:

代码语言:javascript
运行
复制
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fmodule-name - Not found
npm ERR! 404 
npm ERR! 404  '@types/module-name@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)        
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

我尝试过的另一个变体是npm i -D @types/classnames。它继续,但也无济于事

我的tsconfig.json:

代码语言:javascript
运行
复制
{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": false,
    "skipLibCheck": true,
    "strict": true,
    "strictPropertyInitialization": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

我的package.json:

代码语言:javascript
运行
复制
{
    "name": "top-app",
    "version": "0.1.0",
    "private": true,
    "scripts": {
        "dev": "next dev",
        "debug": "set NODE_OPTIONS=--inspect && next dev",
        "build": "next build",
        "start": "next start",
        "lint": "next lint",
        "stylelint": "stylelint \"**/*.css\" --fix"
    },
    "dependencies": {
        "@types/classnames": "^2.3.1",
        "@types/react-router": "^5.1.16",
        "classnames": "^2.3.1",
        "next": "11.1.0",
        "react": "17.0.2",
        "react-dom": "17.0.2",
        "react-router-dom": "^5.3.0"
    },
    "devDependencies": {
        "@babel/plugin-syntax-jsx": "^7.14.5",
        "@types/react": "^17.0.19",
        "@typescript-eslint/eslint-plugin": "^4.29.3",
        "@typescript-eslint/parser": "^4.29.3",
        "eslint": "^7.32.0",
        "eslint-config-next": "11.1.0",
        "eslint-config-prettier": "^8.3.0",
        "eslint-plugin-prettier": "^3.4.1",
        "prettier": "^2.3.2",
        "stylelint": "^13.13.1",
        "stylelint-config-standard": "^22.0.0",
        "stylelint-order": "^4.1.0",
        "stylelint-order-config-standard": "^0.1.3",
        "typescript": "^4.4.2"
    }
}

我该怎么办?太简单的问题请不要打

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-10 18:28:22

这只是一个明显的错误:

代码语言:javascript
运行
复制
<button
        className={cn(styles.button, {
        [styles.primary]: appearance == 'primary',// I used '=' instead of '=='
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
        [styles.ghost]: appearance == 'ghost',
    })}
>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69123538

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档