[英]Error: Module should export a function: i18next
In my Nuxt js application, I installed i18next : 在我的Nuxt js应用程序中,我安装了i18next :
npm install --save-dev i18next
Then whenever I add it to the plugin array in nuxt.config.js as the documentation suggests: 然后,每当我将其添加到nuxt.config.js中的插件数组时,如文档所示:
module.exports = {
build: {
vendor: ['i18next']
}
}
I get this error when I start the sever ( npm run dev
) 启动服务器时出现此错误( npm run dev
)
ERROR Nuxt error
Error: Module should export a function: i18next
- module.js:127 ModuleContainer.addModule
[begueradj]/[nuxt]/lib/core/module.js:127:13
- utils.js:96 promise.then
[begueradj]/[nuxt]/lib/common/utils.js:96:43
- next_tick.js:189 process._tickCallback
internal/process/next_tick.js:189:7
- module.js:696 Function.Module.runMain
module.js:696:11
- bootstrap_node.js:204 startup
bootstrap_node.js:204:16
- bootstrap_node.js:625
bootstrap_node.js:625:3
Why does this happen? 为什么会这样? How to fix it? 如何解决?
The vendor
array is used on Nuxt.js 1.x to help Webpack 3 to optimize build. Nuxt.js 1.x上使用了vendor
阵列,以帮助Webpack 3优化构建。 It's not used to import a lib. 它不用于导入库。
(nb: since Nuxt.js 2.x, that vendor
config is deprecated and can be removed) (nb:自Nuxt.js 2.x起,该vendor
配置已弃用,可以删除)
To import an external lib, you have create a custom Vue.js plugin and to declare it in the nuxt.config.js
in the plugins
array ( https://nuxtjs.org/guide/plugins/ ) 要导入外部库,您需要创建一个自定义的Vue.js插件,并在plugins
数组( https://nuxtjs.org/guide/plugins/ )的nuxt.config.js
中声明它。
module.exports = {
plugins: ['~/plugins/your-cutom-plugins']
}
or, 要么,
you can import your external lib in your component/page/middleware/plugin file to use it directly: 您可以将外部库导入组件/页面/中间件/插件文件中以直接使用它:
<script>
import i18next from 'i18next'
i18next.init({
...
)
</script>
(nb: prefer use install --save
because "i18next" is not only used on dev, but on production too) (nb:更喜欢使用install --save
因为“ i18next”不仅用于开发,而且还用于生产)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.