bitbucket-pipeline 中的 运行 nuxt.js 抛出 'undefined' 错误
Running nuxt.js in bitbucket-pipeline throws 'undefined' error
正在尝试通过 nuxt.js in bitbucket-pipelines 构建静态页面。
但是我在 nuxt generate
步骤中不断收到有趣的错误。它抛出 undefined
的 Nuxt Fatal Error
这里我提供 nuxt.config.js
、bitbucket-pipeline.yml
、package.json
和来自 bitbucket-pipeline 的截图。
nuxt.config.js
require('dotenv').config();
module.exports = {
plugins: [
{ src: '~plugins/i18n.js' }
],
/*
** Headers of the page
*/
head: {
title: 'public-web',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: 'Nuxt.js project' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
]
},
modules: [
'nuxt-i18n',
'@nuxtjs/axios',
'~/modules/hooks'
],
// TODO: LEAVE ONLY LANGUAGES REQUIRED PER TENANT
i18n: {
locales: [
{
code: 'ru',
iso: 'ru-RU',
name: 'Russian',
file: 'ru_RU.json'
},
{
code: 'en',
iso: 'en-US',
name: 'English',
file: 'en.json'
},
{
code: 'de',
iso: 'de-CH',
name: 'Dutch',
file: 'de_CH.json'
},
{
code: 'fr',
iso: 'fr-CH',
name: 'French',
file: 'fr.json'
},
{
code: 'nl-de',
iso: 'nl-NL',
name: 'Dutch',
file: 'nl_NL.json'
}
],
defaultLocale: 'en',
ueI18nLoader: false,
// Separator used to generated routes name for each locale, you shouldn't
// need to change this
routesNameSeparator: '___',
// Suffix added to generated routes name for default locale if strategy is prefix_and_default,
// you shouldn't need to change this
defaultLocaleRouteNameSuffix: 'default',
// Routes generation strategy, can be set to one of the following:
// - 'no_prefix': routes won't be prefixed
// - 'prefix_except_default': add locale prefix for every locale except default
// - 'prefix': add locale prefix for every locale
// - 'prefix_and_default': add locale prefix for every locale and default
strategy: 'prefix',
// Wether or not the translations should be lazy-loaded, if this is enabled,
// you MUST configure langDir option, and locales must be an array of objects,
// each containing a file key
lazy: true,
// Directory that contains translations files when lazy-loading messages,
// this CAN NOT be empty if lazy-loading is enabled
// langDir: null,
langDir: 'locales/',
// Set this to a path to which you want to redirect users accessing root URL (/)
// rootRedirect: 'index.html',
// Enable browser language detection to automatically redirect user
// to their preferred language as they visit your app for the first time
// Set to false to disable
detectBrowserLanguage: {
// If enabled, a cookie is set once a user has been redirected to his
// preferred language to prevent subsequent redirections
// Set to false to redirect every time
useCookie: true,
// Cookie name
cookieKey: 'i18n_redirected',
// Set to always redirect to value stored in the cookie, not just once
alwaysRedirect: false,
// If no locale for the browsers locale is a match, use this one as a fallback
fallbackLocale: 'en'
},
// TODO: Uncomment for dev
// detectBrowserLanguage: false,
// If true, SEO metadata is generated for routes that have i18n enabled.
// Note that performance can suffer with this enabled and there might be compatibility
// issues with some plugins. Recommended way is to set up SEO as described in:
// https://nuxt-community.github.io/nuxt-i18n/seo.html#improving-performance
// TODO: Enable on prod
seo: false,
// Fallback base URL to use as prefix for alternate URLs in hreflang tags.
// By default VueRouter's base URL will be used and only if that is not available,
// fallback URL will be used.
// TODO: Replace by prod domain
baseUrl: 'http://localhost:3000/',
vueI18n: {
fallbackLocale: 'en'
},
// Called right before app's locale changes
// beforeLanguageSwitch: (oldLocale, newLocale) => null,
// // Called after app's locale has changed
// onLanguageSwitched: (oldLocale, newLocale) => null
},
axios: {},
css: [
'@/assets/styles/main.scss'
],
/*
** Customize the progress bar color
*/
loading: { color: '#3B8070' },
loaders: {
// file: {},
// fontUrl: { limit: 1000 },
imgUrl: {
limit: 1000,
fallback: require.resolve('responsive-loader'),
quality: 85
},
// pugPlain: {},
// vue: {
// transformAssetUrls: {
// video: 'src',
// source: 'src',
// object: 'src',
// embed: 'src'
// }
// },
// css: {},
// cssModules: {
// localIdentName: '[local]_[hash:base64:5]'
// },
// sass: {
// indentedSyntax: true
// },
// scss: {},
// stylus: {},
// vueStyle: {}
},
/*
** Build configuration
*/
build: {
/*
** Run ESLint on save
*/
extend (config, { isDev, isClient, loaders }) {
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
}
}
}
};
bitbucket-pipeline.yml
pipelines:
branches:
master:
- step:
name: Build and Test Static Pages
deployment: public-web
image: node:current
cache:
- node
script:
- npm install
- npm run precommit
- npm run generate
package.json
{
"name": "public-web",
"version": "1.0.0",
"description": "Nuxt.js project",
"author": "test@dev.com",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"precommit": "npm run lint"
},
"dependencies": {
"@nuxtjs/axios": "^5.8.0",
"nuxt": "2.10",
"nuxt-i18n": "^6.4.0"
},
"devDependencies": {
"@lokalise/node-api": "^1.4.0",
"babel-eslint": "^10.0.1",
"dotenv": "^8.2.0",
"eslint": "^4.19.1",
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^2.1.1",
"eslint-plugin-vue": "^4.0.0",
"fs-extra": "^8.1.0",
"node-sass": "^4.13.0",
"prettier": "1.19.1",
"request": "^2.88.0",
"responsive-loader": "^1.2.0",
"sass-loader": "^8.0.0",
"unzipper": "^0.10.5"
}
}
如有任何帮助,我们将不胜感激。提前致谢!
问题似乎出在 npm
模块之一。准确地说,问题出在 @lokalise/node-api
。
当提供无效的信用时,这个包将抛出无用的错误。
如果有人遇到同样的问题,我希望这会有所帮助
正在尝试通过 nuxt.js in bitbucket-pipelines 构建静态页面。
但是我在 nuxt generate
步骤中不断收到有趣的错误。它抛出 undefined
Nuxt Fatal Error
这里我提供 nuxt.config.js
、bitbucket-pipeline.yml
、package.json
和来自 bitbucket-pipeline 的截图。
nuxt.config.js
require('dotenv').config();
module.exports = {
plugins: [
{ src: '~plugins/i18n.js' }
],
/*
** Headers of the page
*/
head: {
title: 'public-web',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: 'Nuxt.js project' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
]
},
modules: [
'nuxt-i18n',
'@nuxtjs/axios',
'~/modules/hooks'
],
// TODO: LEAVE ONLY LANGUAGES REQUIRED PER TENANT
i18n: {
locales: [
{
code: 'ru',
iso: 'ru-RU',
name: 'Russian',
file: 'ru_RU.json'
},
{
code: 'en',
iso: 'en-US',
name: 'English',
file: 'en.json'
},
{
code: 'de',
iso: 'de-CH',
name: 'Dutch',
file: 'de_CH.json'
},
{
code: 'fr',
iso: 'fr-CH',
name: 'French',
file: 'fr.json'
},
{
code: 'nl-de',
iso: 'nl-NL',
name: 'Dutch',
file: 'nl_NL.json'
}
],
defaultLocale: 'en',
ueI18nLoader: false,
// Separator used to generated routes name for each locale, you shouldn't
// need to change this
routesNameSeparator: '___',
// Suffix added to generated routes name for default locale if strategy is prefix_and_default,
// you shouldn't need to change this
defaultLocaleRouteNameSuffix: 'default',
// Routes generation strategy, can be set to one of the following:
// - 'no_prefix': routes won't be prefixed
// - 'prefix_except_default': add locale prefix for every locale except default
// - 'prefix': add locale prefix for every locale
// - 'prefix_and_default': add locale prefix for every locale and default
strategy: 'prefix',
// Wether or not the translations should be lazy-loaded, if this is enabled,
// you MUST configure langDir option, and locales must be an array of objects,
// each containing a file key
lazy: true,
// Directory that contains translations files when lazy-loading messages,
// this CAN NOT be empty if lazy-loading is enabled
// langDir: null,
langDir: 'locales/',
// Set this to a path to which you want to redirect users accessing root URL (/)
// rootRedirect: 'index.html',
// Enable browser language detection to automatically redirect user
// to their preferred language as they visit your app for the first time
// Set to false to disable
detectBrowserLanguage: {
// If enabled, a cookie is set once a user has been redirected to his
// preferred language to prevent subsequent redirections
// Set to false to redirect every time
useCookie: true,
// Cookie name
cookieKey: 'i18n_redirected',
// Set to always redirect to value stored in the cookie, not just once
alwaysRedirect: false,
// If no locale for the browsers locale is a match, use this one as a fallback
fallbackLocale: 'en'
},
// TODO: Uncomment for dev
// detectBrowserLanguage: false,
// If true, SEO metadata is generated for routes that have i18n enabled.
// Note that performance can suffer with this enabled and there might be compatibility
// issues with some plugins. Recommended way is to set up SEO as described in:
// https://nuxt-community.github.io/nuxt-i18n/seo.html#improving-performance
// TODO: Enable on prod
seo: false,
// Fallback base URL to use as prefix for alternate URLs in hreflang tags.
// By default VueRouter's base URL will be used and only if that is not available,
// fallback URL will be used.
// TODO: Replace by prod domain
baseUrl: 'http://localhost:3000/',
vueI18n: {
fallbackLocale: 'en'
},
// Called right before app's locale changes
// beforeLanguageSwitch: (oldLocale, newLocale) => null,
// // Called after app's locale has changed
// onLanguageSwitched: (oldLocale, newLocale) => null
},
axios: {},
css: [
'@/assets/styles/main.scss'
],
/*
** Customize the progress bar color
*/
loading: { color: '#3B8070' },
loaders: {
// file: {},
// fontUrl: { limit: 1000 },
imgUrl: {
limit: 1000,
fallback: require.resolve('responsive-loader'),
quality: 85
},
// pugPlain: {},
// vue: {
// transformAssetUrls: {
// video: 'src',
// source: 'src',
// object: 'src',
// embed: 'src'
// }
// },
// css: {},
// cssModules: {
// localIdentName: '[local]_[hash:base64:5]'
// },
// sass: {
// indentedSyntax: true
// },
// scss: {},
// stylus: {},
// vueStyle: {}
},
/*
** Build configuration
*/
build: {
/*
** Run ESLint on save
*/
extend (config, { isDev, isClient, loaders }) {
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
}
}
}
};
bitbucket-pipeline.yml
pipelines:
branches:
master:
- step:
name: Build and Test Static Pages
deployment: public-web
image: node:current
cache:
- node
script:
- npm install
- npm run precommit
- npm run generate
package.json
{
"name": "public-web",
"version": "1.0.0",
"description": "Nuxt.js project",
"author": "test@dev.com",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"precommit": "npm run lint"
},
"dependencies": {
"@nuxtjs/axios": "^5.8.0",
"nuxt": "2.10",
"nuxt-i18n": "^6.4.0"
},
"devDependencies": {
"@lokalise/node-api": "^1.4.0",
"babel-eslint": "^10.0.1",
"dotenv": "^8.2.0",
"eslint": "^4.19.1",
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^2.1.1",
"eslint-plugin-vue": "^4.0.0",
"fs-extra": "^8.1.0",
"node-sass": "^4.13.0",
"prettier": "1.19.1",
"request": "^2.88.0",
"responsive-loader": "^1.2.0",
"sass-loader": "^8.0.0",
"unzipper": "^0.10.5"
}
}
如有任何帮助,我们将不胜感激。提前致谢!
问题似乎出在 npm
模块之一。准确地说,问题出在 @lokalise/node-api
。
当提供无效的信用时,这个包将抛出无用的错误。
如果有人遇到同样的问题,我希望这会有所帮助