import R from "ramda"
function useMiddlewares(app) {
return R.map(R.compose(
R.map(i => i(app)), // app
require, //
i => `${r("./middlewares")}/${i}` //
)
}
useMiddlewares(["general", "database", "router"])
the above code is fine in the development environment, but after packaging, the following error occurs in the formal environment:
/Users/xuyuechao/Work/other-git-project/nuxt-koa/build/main.js:243
return !(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = "MODULE_NOT_FOUND"; throw e; }());
^
Error: Cannot find module "."
at webpackMissingModule (/Users/xuyuechao/Work/other-git-project/nuxt-koa/build/main.js:243:60)
at /Users/xuyuechao/Work/other-git-project/nuxt-koa/build/main.js:243:18
at /Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/_ramda@0.23.0@ramda/src/internal/_pipe.js:3:14
at /Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/_ramda@0.23.0@ramda/src/internal/_pipe.js:3:27
at /Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/_ramda@0.23.0@ramda/src/internal/_arity.js:5:45
at _map (/Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/_ramda@0.23.0@ramda/src/internal/_map.js:6:19)
at map (/Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/_ramda@0.23.0@ramda/src/map.js:57:14)
at /Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/_ramda@0.23.0@ramda/src/internal/_dispatchable.js:39:15
at /Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/_ramda@0.23.0@ramda/src/internal/_curry2.js:20:46
at f1 (/Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/_ramda@0.23.0@ramda/src/internal/_curry1.js:17:17)
at new Server (/Users/xuyuechao/Work/other-git-project/nuxt-koa/build/main.js:228:5)
at Object.<anonymous> (/Users/xuyuechao/Work/other-git-project/nuxt-koa/build/main.js:306:11)
at Object.<anonymous> (/Users/xuyuechao/Work/other-git-project/nuxt-koa/build/main.js:308:30)
at __webpack_require__ (/Users/xuyuechao/Work/other-git-project/nuxt-koa/build/main.js:22:30)
at module.exports.module.exports.head.title (/Users/xuyuechao/Work/other-git-project/nuxt-koa/build/main.js:68:18)
at Object.<anonymous> (/Users/xuyuechao/Work/other-git-project/nuxt-koa/build/main.js:3:10)
at first I thought that the asking price name would be changed after packaging and compilation, so I reported an error, but after trying it out, I found that it had nothing to do with this. There are no ideas now, experts from all sides, let"s see if we can provide some ideas
< H1 > add < / H1 >I tried again and found that the above code could be reduced to:
import { resolve } from "path"
const r = path => resolve(__dirname, path)
require(r("./middlewares/general"))
the error message remains the same, but when I change the above code to:
require("usr/local/middlewares/general")
there is no problem, that is, it is not possible to use the r function to assemble the path, and there is no problem to use the absolute path directly. But why is there nothing wrong with the development environment, but not the formal environment, or is it confusing?