import fs from 'fs'
import {resolve} from 'path'
let config=JSON.parse(fs.readFileSync(`${resolve(__dirname,'./production.config.json')}`,'utf-8'))
export default config
这个是config文件
import {Nuxt, Builder} from 'nuxt'
import Koa from 'koa'
import R from 'ramda'
var cors = require('koa2-cors');
import {resolve} from 'path'
import MIDDLEWARES from './middlewares'
import conf from './config/index'
let config = require('../nuxt.config.js')
这个是server里index文件,dev环境没问题,但是build之后配置文件路径有问题提示文件找不到
/
Error: ENOENT: no such file or directory, open 'C:\production.config.json'
at Object.fs.openSync (fs.js:646:18)
at Object.fs.readFileSync (fs.js:551:33)
at Object.<anonymous> (C:\project\nuxtkoa\build\webpack:\server\config\index.js:3:26)
at Object.module.exports.module.exports.head.title (C:\project\nuxtkoa\build\main.js:219:30)
at __webpack_require__ (C:\project\nuxtkoa\build\webpack:\webpack\bootstrap 0d535cff614e475cff89:19:1)
at Object.<anonymous> (C:\project\nuxtkoa\build\webpack:\server\index.js:1:1)
at Object.<anonymous> (C:\project\nuxtkoa\build\main.js:163:30)
at __webpack_require__ (C:\project\nuxtkoa\build\webpack:\webpack\bootstrap 0d535cff614e475cff89:19:1)
at C:\project\nuxtkoa\build\webpack:\webpack\bootstrap 0d535cff614e475cff89:62:1
at Object.<anonymous> (C:\project\nuxtkoa\build\main.js:68:10)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
npm ERR! code ELIFECYCLE
错误地点
let config = JSON.parse(__WEBPACK_IMPORTED_MODULE_0_fs___default.a.readFileSync(`${Object(__WEBPACK_IMPORTED_MODULE_1_path__["resolve"])(__dirname, './production.config.json')}`, 'utf-8'));
/* harmony default export */ __webpack_exports__["a"] = (config);
/* WEBPACK VAR INJECTION */}.call(__webpack_exports__, "/"))