我使用yarn create nuxt-app <my-project>
和Koa创建了一个nuxt应用。
我使用fastify-nuxt创建了第二个index.js文件,该文件曾经可以工作,但是现在我遇到了一些讨厌的错误:
error in ./.nuxt/client.js
Module build failed: TypeError: this.setDynamic is not a function
at PluginPass.pre (/media/DarkHawk/srv/NodesProjects//mainWebsite/node_modules/babel-plugin-transform-runtime/lib/index.js:31:12)
at transformFile (/media/DarkHawk/srv/NodesProjects//mainWebsite/node_modules/@babel/core/lib/transformation/index.js:78:27)
at runSync (/media/DarkHawk/srv/NodesProjects//mainWebsite/node_modules/@babel/core/lib/transformation/index.js:45:3)
at runAsync (/media/DarkHawk/srv/NodesProjects//mainWebsite/node_modules/@babel/core/lib/transformation/index.js:35:14)
at process.nextTick (/media/DarkHawk/srv/NodesProjects/__/mainWebsite/node_modules/@babel/core/lib/transform.js:34:34)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
@ multi webpack-hot-middleware/client?name=client&reload=true&timeout=30000&path=/__webpack_hmr ./.nuxt/client.js
我的packages.json看起来像这样:
{
"name": "test",
"version": "1.0.0",
"description": "My groundbreaking Nuxt.js project",
"author": "Gogs",
"private": true,
"scripts": {
"dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server",
"devfast": "cross-env NODE_ENV=development nodemon server/indexfas.js --watch server",
"build": "nuxt build",
"start": "cross-env NODE_ENV=production node server/index.js",
"generate": "nuxt generate",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"precommit": "npm run lint"
},
"dependencies": {
"@nuxtjs/axios": "^5.0.0",
"cookie": "^0.3.1",
"cross-env": "^5.2.0",
"fastify": "^1.12.1",
"fastify-nuxt": "^1.0.12",
"fastify-vue-plugin": "^1.2.3",
"iview": "^3.1.3",
"js-cookie": "^2.2.0",
"koa": "^2.5.2",
"koa-router": "^7.4.0",
"nuxt": "^2.0.0",
"paseto.js": "^0.1.2",
"pg": "^7.5.0",
"secure-password": "^3.1.0",
"vue-loader": "^14.2.2"
},
"devDependencies": {
"eslint": "^5.0.1",
"eslint-config-prettier": "^3.1.0",
"eslint-loader": "^2.0.0",
"eslint-plugin-prettier": "2.6.2",
"eslint-plugin-vue": "^4.0.0",
"nodemon": "^1.11.0",
"prettier": "1.14.3"
}
}
还有我的indexfas.js:
const host = process.env.HOST || '127.0.0.1'
const port = process.env.PORT || 3000
const fastify = require('fastify')()
const nuxtConfig = require('../nuxt.config')
fastify.register(require('fastify-nuxt'), nuxtConfig)
fastify.ready()
fastify.listen(port, () => {
consola.info('> Listening on port 3000')
})
我该怎么做才能使固定效果正常?为什么会出现此错误? 几个月前,在使用fastify创建新的Nuxt项目时,我没有出现此错误。也许有些事情我做得不好?
谢谢!
编辑:安装了很多软件包之后,我终于开始了它而没有抛出错误:
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@babel/traverse": "^7.1.4"
我的nuxt.config.js文件构建部分:
build: {
analyze: true,
babel: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-syntax-dynamic-import']
},
// filenames: {
// chunk: ({ isDev }) => (isDev ? '[name].js' : '[id].[chunkhash].js')
// },
/*
** You can extend webpack config here
*/
extend(config, ctx) {
// Run ESLint on save
if (ctx.isDev && ctx.isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
}
}
}
但是只有fastify内部定义的路由有效,nuxt路由无效,并且返回未找到的PAge。