简体   繁体   English

找不到模块的声明文件。 '/path/to/module-name.js'隐式具有'any'类型

[英]Could not find a declaration file for module. '/path/to/module-name.js' implicitly has an 'any' type

I am going through the Gatsby.js tutorial and in tutorial two, you have to import some fonts. 我正在阅读Gatsby.js教程,在第二个教程中,您必须导入一些字体。 When I try to import theme lawton I see this error under import lawtonTheme from "typography-theme-lawton"; 当我尝试导入theme lawton我在import lawtonTheme from "typography-theme-lawton";下看到此错误import lawtonTheme from "typography-theme-lawton";

I first did npm install --save typography-theme-lawton 我首先做了npm install --save typography-theme-lawton

  Could not find a declaration file for module 'typography-theme-lawton'. '/Users/react/tutorial-part-two/node_modules/typography-theme-lawton/dist/index.js' implicitly has an 'any' type.
  Try `npm install @types/typography-theme-lawton` if it exists or add a new declaration (.d.ts) file containing `declare module 'typography-theme-lawton';`

This is my typography.js file: 这是我的typography.js文件:

import Typography from "typography";
//import bootstrapTheme from " typography-theme-bootstrap";
import lawtonTheme from "typography-theme-lawton";

const typography = new Typography(lawtonTheme);

//const typography = new Typography({ baseFontSize: "18px" });
//const typography = new Typography(bootstrapTheme);

export default typography;

This is my gatsby-config.js file: 这是我的gatsby-config.js文件:

  module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-typography`,
      options: {
        pathToConfigModule: `src/utils/typography.js`
      }
    }
  ]
};

Also in the gatsby-config file, the word module is underline and this note shows: [ts] File is a CommonJS module; it may be converted to an ES6 module. [80001] 同样在gatsby-config文件中,单词module是带下划线的,此注释显示: [ts] File is a CommonJS module; it may be converted to an ES6 module. [80001] [ts] File is a CommonJS module; it may be converted to an ES6 module. [80001]

I also tried npm install @types/typography-theme-lawton but it gave me errors 我也尝试过npm install @types/typography-theme-lawton但这给了我错误

Based on your your problem,I guess you are using typescript, and the project can't find the ts module. 根据您的问题,我想您正在使用打字稿,并且该项目找不到ts模块。 You need to install ts files.Try this: 您需要安装ts文件。尝试以下操作:

npm install —-save @types/.....

Or, you can add a d.ts file in your project somewhere, and add the above in the file. 或者,您可以在项目中的某个位置添加d.ts文件,然后在文件中添加以上内容。

declare module typography-theme-lawton

[ts] File is a CommonJS module; [ts]文件是CommonJS模块; it may be converted to an ES6 module. 可以将其转换为ES6模块。 [80001] [80001]

I assume you are using VSCode.Add this in the setting to enable it: 我假设您正在使用VSCode。在设置中添加此功能以启​​用它:

"javascript.suggestionActions.enabled": false

PS: It's just a suggestion,so you can just ignore this. PS:这只是一个建议,因此您可以忽略此。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到模块'../constants/links'的声明文件| src / constants / links.js'隐式具有'any'类型 - Could not find a declaration file for module '../constants/links' | src/constants/links.js' implicitly has an 'any' type 无法找到隐式具有“任何”类型的模块的声明文件 - 在导入部分 CommonJS 模块时 - Could not find a declaration file for module implicitly has an 'any' type - while importing part of CommonJS module 反应/节点构建错误。 找不到模块“历史”的声明文件。 'node_modules/history/index.js' 隐含一个 'any' 类型 - React/node build error. Could not find a declaration file for module 'history'. 'node_modules/history/index.js' implicitly has an 'any' type 找不到模块的声明文件 - Could not find a declaration file for module NodeJs 找不到模块。 路径和名称正确 - NodeJs Cannot Find Module. Path and name are correct 找不到模块 'bootstrap/dist/js/bootstrap 的声明文件 - Could not find a declaration file for module 'bootstrap/dist/js/bootstrap 无法找到模块'drivelist'的声明文件 - Could not find a declaration file for module 'drivelist' 找不到模块“react”的声明文件 - Could not find a declaration file for module 'react' 在反应中找不到模块错误的声明文件 - Could not find a declaration file for module error in react 找不到模块“mymodule”的声明文件 - Could not find a declaration file for module 'mymodule'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM