gpt4 book ai didi

javascript - Nextjs-Graphql webpack加载器: How to integrate Nextjs with Graphql loader

转载 作者:行者123 更新时间:2023-11-29 18:48:18 30 4
gpt4 key购买 nike

我正在尝试将 Nextjs 与 graphql-tag/loader 集成,这是我的 next.config.js 文件:

const withSass = require('@zeit/next-sass')
const graphqlLoader = require('graphql-tag/loader')

module.exports = withSass({
webpack: (config, { buildId, dev, isServer, defaultLoaders }) => {
config.module.rules.push({
test: /\.(graphql|gql)$/,
loader: graphqlLoader,
exclude: /node_modules/
})

return config
}
})

我无法构建,出现以下错误:

/HOME/node_modules/graphql-tag/loader.js:43
this.cacheable();
^
TypeError: Cannot read property 'cacheable' of undefined

请帮忙。

最佳答案

我让它在我的设置中工作如下。不确定你的代码有什么问题,但你可以试试看它是否有效:)你可以使用下一个 js 插件。也许插件的顺序很重要。这是我的配置。还有一些额外的代码,但我相信,你会从中得到你需要的。至于库版本 "next": "6.1.1", "next-optimized-images": "1.4.1", "next-plugin-graphql": "^0.0.1",

const withSass = require("@zeit/next-sass");
const webpack = require("webpack");
const withGraphQL = require("next-plugin-graphql");
const withOptimizedImages = require("next-optimized-images");

module.exports = withOptimizedImages(
withGraphQL(
withSass({
cssModules: true,
cssLoaderOptions: {
importLoaders: 1,
localIdentName: "[local]___[hash:base64:5]"
},
webpack: config => {

config.plugins.push(
new webpack.ContextReplacementPlugin(
/graphql-language-service-interface[\\/]dist$/,
new RegExp(`^\\./.*\\.js$`)
)
);

return config;
}
})
)
);

如果您只想修改代码而不安装插件,您可以从这个 next-graphql-plugin 中获得启发。 .该插件对我有用,与您的设置不同的是它们的规则配置如下

  config.module.rules.push({
test: /\.(graphql|gql)$/,
include: [dir],
exclude: /node_modules/,
use: [
{
loader: 'graphql-tag/loader'
}
]
})

关于javascript - Nextjs-Graphql webpack加载器: How to integrate Nextjs with Graphql loader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52372233/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com