[英]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
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.