nuxt-community / koa-template

Starter template for Nuxt.js with KoaJS.
https://koa.nuxtjs.org
382 stars 62 forks source link

Production caused the file directory to change using require error #48

Closed xuxchao closed 6 years ago

xuxchao commented 6 years ago
import { resolve } from 'path'
const r = path => resolve(__dirname, path)
require(r('./middlewares/general'))

error

/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)

How can I avoid this? The solution I came up with is 1. Change the packing method, and the file directory remains unchanged. 2. Be able to modify these imports into a packaged path。 But don't know how to change webpack

This question is available on Nuxt community (#c31)
ghost commented 6 years ago

This issue as been imported as question since it does not respect koa-template issue template. Only bug reports and feature requests stays open to reduce maintainers workload. If your issue is not a question, please mention the repo admin or moderator to change its type and it will be re-opened automatically. Your question is available at https://cmty.app/nuxt/koa-template/issues/c31.