我试图添加额外的盖茨比插件到盖茨比项目。我想在gatsby-config.js文件中添加‘gatsby-plugin样式-组件’。任何帮助都将不胜感激。新手反应迅速,学得很快。
已经添加并在运行npm run build后向各地抛出错误
/**
* Configure your Gatsby site with this file.
*
* See: https://www.gatsbyjs.org/docs/gatsby-config/
*/
module.exports = {
plugins: [`gatsby-plugin-emotion`],
}gatsby hello-world@0.1.0构建/Users/jappleman/code/hello-world/tutorial-part-two 盖茨比建筑
error We encountered an error while trying to load your site's gatsby-config.
Please fix the error and try again.
Error: /Users/jappleman/code/hello-world/tutorial-part-two/gatsby-config.js:8
plugins: ['`gatsby-plugin-emotion`],['`gatsby-plugin-styled-components'],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unterminated template literal
- v8-compile-cache.js:226 NativeCompileCache._moduleCompile
[tutorial-part-two]/[v8-compile-cache]/v8-compile-cache.js:226:18
- v8-compile-cache.js:172 Module._compile
[tutorial-part-two]/[v8-compile-cache]/v8-compile-cache.js:172:36
- loader.js:712 Object.Module._extensions..js
internal/modules/cjs/loader.js:712:10
- loader.js:600 Module.load
internal/modules/cjs/loader.js:600:32
- loader.js:539 tryModuleLoad
internal/modules/cjs/loader.js:539:12
- loader.js:531 Function.Module._load
internal/modules/cjs/loader.js:531:3
- loader.js:637 Module.require
internal/modules/cjs/loader.js:637:17
- v8-compile-cache.js:159 require
[tutorial-part-two]/[v8-compile-cache]/v8-compile-cache.js:159:20
- get-config-file.js:33
[tutorial-part-two]/[gatsby]/dist/bootstrap/get-config-file.js:33:22
- Generator.next
- new Promise发布于 2019-05-20 11:48:02
. an导出对象
module.exports = {}
在该对象中,要在项目中使用的plugins被指定为已安装为项目依赖项的插件名称( 数组 of plugin name,字符串)(例如,在终端中键入npm install gatsby-plugin-react-helmet或yarn add gatsby-plugin-react-helmet )。
module.exports = {
plugins: [
`gatsby-plugin-react-helmet`
]
}但是,您将安装的一些插件可能需要设置一些选项才能正常工作。因此,每个插件都应该指定为同一插件数组中的一个对象。在这种情况下,每个对象的resolve属性的值是插件的名称,通常后面跟着他们自己的options的对象。
module.exports = {
plugins: [
`gatsby-plugin-react-helmet`,
`gatsby-transformer-remark`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `src`,
path: `${__dirname}/src/data/`
}
}
]
}有关更多信息,请参见在您的站点中使用插件
此外,考虑到您的错误是由SyntaxError引起的,请参阅文字获取有关backticks与常规引号的信息,它们之间的差异如下:
`gatsby-plugin-styled-components` & 'gatsby-plugin-styled-components'&为什么下面的行可能导致未终止字符串文本SyntaxError
plugins: ['`gatsby-plugin-emotion`],['`gatsby-plugin-styled-components']在此之后,如果解决方案不明显,请尝试将plugins更改为以下任一项:
plugins: [`gatsby-plugin-emotion`],[`gatsby-plugin-styled-components`]或
plugins: ['gatsby-plugin-emotion'],['gatsby-plugin-styled-components']https://stackoverflow.com/questions/56201588
复制相似问题