Activities

Perlover

Perlover posted a new question

koa-template •

server/index.js - there is circular reference - it's potential memory leak

Hello!

I generated koa template for nuxt and i see there:

  app.use((ctx) => {
    ctx.status = 200
    ctx.respond = false // Bypass Koa's built-in response handling
    ctx.req.ctx = ctx // This might be useful later on, e.g. in nuxtServerInit or with nuxt-stash
    nuxt.render(ctx.req, ctx.res)
  })

But i think there is circular reference and this is a potential memory leak

I would did by this way:

  app.use((ctx) => {
    ctx.status = 200
    ctx.respond = false // Bypass Koa's built-in response handling
    ctx.req.ctx = ctx // This might be useful later on, e.g. in nuxtServerInit or with nuxt-stash
    nuxt.render(ctx.req, ctx.res)
    ctx.req.ctx = null
  })
Perlover

Perlover posted a new question

koa-template •

server/index.js - there is circular reference - is it memory leak here?

Hello!

I generated koa template for nuxt and i see there:

  app.use((ctx) => {
    ctx.status = 200
    ctx.respond = false // Bypass Koa's built-in response handling
    ctx.req.ctx = ctx // This might be useful later on, e.g. in nuxtServerInit or with nuxt-stash
    nuxt.render(ctx.req, ctx.res)
  })

But i think there is circular reference and this is a potential memory leak

I would did by this way:

  app.use((ctx) => {
    ctx.status = 200
    ctx.respond = false // Bypass Koa's built-in response handling
    ctx.req.ctx = ctx // This might be useful later on, e.g. in nuxtServerInit or with nuxt-stash
    nuxt.render(ctx.req, ctx.res)
    ctx.req.ctx = null
  })

What do you think?

ndekross

ndekross resolved the question #c46

koa-template •

Koa server doesn't run on Heroku (production)
ndekross

ndekross posted a new question

koa-template •

Koa server doesn't run on Heroku (production)

Hi,

I'm running Nuxt in Universal Mode with Koa as API / Controller in the backup based on the Koa template. I'm deploying to Heroku. API works fine locally, but returns 404 in production. I think that the app is running as SPA when deployed.

Here's my server/index.js

const Koa = require('koa')
const consola = require('consola')
const Router = require('koa-router');
const { Nuxt, Builder } = require('nuxt')
const api = require('./api');

console.log('server works'); // This line gets ignored by the Heroku console

const app = new Koa()
const router = new Router();

// Import and Set Nuxt.js options
const config = require('../nuxt.config.js')
config.dev = app.env !== 'production'

router.use('/api', api.routes(), api.allowedMethods());
app.use(router.routes());

async function start () {
  // Instantiate nuxt.js
  const nuxt = new Nuxt(config)

  const {
    host = process.env.HOST || '127.0.0.1',
    port = process.env.PORT || 3000
  } = nuxt.options.server

  // Build in development
  if (config.dev) {
    const builder = new Builder(nuxt)
    await builder.build()
  } else {
    await nuxt.ready()
  }

  app.use((ctx) => {
    ctx.status = 200
    ctx.respond = false // Bypass Koa's built-in response handling
    ctx.req.ctx = ctx // This might be useful later on, e.g. in nuxtServerInit or with nuxt-stash
    nuxt.render(ctx.req, ctx.res)
  })

  app.listen(port, host)
  consola.ready({
    message: `Server listening on http://${host}:${port}`, // Neither this line appears in Heroku console
    badge: true 
  })
}

start()

Procfile

web: nuxt start

Scripts from package.json

"scripts": {
    "dev": "cross-env HOST=192.168.1.65 NODE_ENV=development nodemon server/index.js --watch server ",
    "build": "nuxt build",
    "start": "cross-env NODE_ENV=production node server/index.js",
    "generate": "nuxt generate",
    "test": "ava",
    "test:unit": "cross-env TEST=unit ava --config unit.config.js",
    "test:e2e": "cross-env TEST=e2e ava --config e2e.config.js",
    "heroku-postbuild": "nuxt build"
  }

I think I'm getting nu(x)ts after reading all this deployment docs not seeing the obvious.

Thanks,
Natanael

EThan-Jam

EThan-Jam posted a new question

koa-template •

Module build failed: Error: Plugin/Preset files are not allowed to export objects,

刚按照教程 搭建 了 nuxt ,并 npm i 安装了 依赖项,使用npm run dev 报错了
Module build failed: Error: Plugin/Preset files are not allowed to export objects,

fireairforce

fireairforce posted a new question

koa-template •

Why not update the installation of the framework to solve the question in the begining?

I see many people use this framework meet the same question when they use npm run dev to get this project start,bug they will get some bugs on the installation just like this issue…

so i think if so many people meet the same questions why not update the installation of this framework? :)

fireairforce

fireairforce posted a new question

koa-template •

Why not update the installation of the framework to solve the question in the begining?

I see many people use this framework meet the same question when they use npm run dev to get this project start,bug they will get some bugs on the installation just like this issue

so i think if so many people meet the same questions why not update the installation of this framework? :)

5201314999

5201314999 posted a new question

koa-template •

it's time to update to vue-cli3

I think it is time to update to vue-cli3 and fix some errors now

gotenxds

gotenxds posted a new question

koa-template •

Http2 error for bypassing koa response handling

On line 24 we bypass koa default response handling, this also bypasses logic added in https://github.com/koajs/koa/pull/1264
Which adds support for http2 status handling (removing messages)

ChenDuan

ChenDuan posted a new question

koa-template •

Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions.

Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions. In G:\nuxt-learn\nodemodules\backpack-core\babel.js at createDescriptor (G:\nuxt-learn\nodemodules\@babel\core\lib\config\config-descriptors.js:178:11)
at items.map (G:\nuxt-learn\nodemodules\@babel\core\lib\config\config-descriptors.js:109:50) at Array.map (<anonymous>) at createDescriptors (G:\nuxt-learn\nodemodules\@babel\core\lib\config\config-descriptors.js:109:29)
at createPresetDescriptors (G:\nuxt-learn\nodemodules\@babel\core\lib\config\config-descriptors.js:101:10) at passPerPreset (G:\nuxt-learn\nodemodules\@babel\core\lib\config\config-descriptors.js:58:96)
at cachedFunction (G:\nuxt-learn\nodemodules\@babel\core\lib\config\caching.js:33:19) at presets.presets (G:\nuxt-learn\nodemodules\@babel\core\lib\config\config-descriptors.js:29:84)
at mergeChainOpts (G:\nuxt-learn\nodemodules\@babel\core\lib\config\config-chain.js:320:26) at G:\nuxt-learn\nodemodules\@babel\core\lib\config\config-chain.js:283:7

module.js:550
throw err;
^

Error: Cannot find module 'G:\nuxt-learn\build\main.js'
at Function.Module.resolveFilename (module.js:548:15) at Function.Module.load (module.js:475:25)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrapnode.js:204:16) at bootstrapnode.js:625:3

achillesz

achillesz posted a new question

koa-template •

vue init nuxt-community/koa-template nuxt-learn

npm run dev

ERROR Failed to compile with 1 errors 18:43:53

error in ./server/index.js

Module build failed: Error: Plugin/Preset files are not allowed to export objects
, only functions. In /Users/achilles/yilong/nuxt-learn/node_modules/backpack-core
/babel.js

imdunkind

imdunkind posted a new question

koa-template •

Module build failed: Error: Plugin/Preset files are not allowed

`[email protected]:~/NODEJS/testtest$ npm run dev

[email protected] dev /home/imdunkind/NODEJS/testtest
backpack dev

ERROR Failed to compile with 1 errors 11:06:43

error in ./server/index.js

Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions. In /home/imdunkind/NODEJS/testtest/nodemodules/backpack-core/babel.js at createDescriptor (/home/imdunkind/NODEJS/testtest/nodemodules/@babel/core/lib/config/config-descriptors.js:178:11)
at items.map (/home/imdunkind/NODEJS/testtest/nodemodules/@babel/core/lib/config/config-descriptors.js:109:50) at Array.map (<anonymous>) at createDescriptors (/home/imdunkind/NODEJS/testtest/nodemodules/@babel/core/lib/config/config-descriptors.js:109:29)
at createPresetDescriptors (/home/imdunkind/NODEJS/testtest/nodemodules/@babel/core/lib/config/config-descriptors.js:101:10) at passPerPreset (/home/imdunkind/NODEJS/testtest/nodemodules/@babel/core/lib/config/config-descriptors.js:58:96)
at cachedFunction (/home/imdunkind/NODEJS/testtest/nodemodules/@babel/core/lib/config/caching.js:33:19) at presets.presets (/home/imdunkind/NODEJS/testtest/nodemodules/@babel/core/lib/config/config-descriptors.js:29:84)
at mergeChainOpts (/home/imdunkind/NODEJS/testtest/nodemodules/@babel/core/lib/config/config-chain.js:320:26) at /home/imdunkind/NODEJS/testtest/nodemodules/@babel/core/lib/config/config-chain.js:283:7

internal/modules/cjs/loader.js:605
throw err;
^

Error: Cannot find module '/home/imdunkind/NODEJS/testtest/build/main.js'
at Function.Module.resolveFilename (internal/modules/cjs/loader.js:603:15) at Function.Module.load (internal/modules/cjs/loader.js:529:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:775:12)
at startup (internal/bootstrap/node.js:300:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:826:3)`

package.json
{ "name": "testtest", "version": "1.1.0", "description": "Nuxt.js project", "author": "", "private": true, "scripts": { "dev": "backpack dev", "build": "nuxt build && backpack build", "start": "cross-env NODE_ENV=production node build/main.js", "precommit": "npm run lint", "lint": "eslint --ext .js,.vue --ignore-path .gitignore ." }, "dependencies": { "cross-env": "^5.0.1", "koa": "^2.4.1", "nuxt": "latest", "source-map-support": "^0.4.15" }, "devDependencies": { "babel-eslint": "^7.1.1", "backpack-core": "^0.3.0", "eslint": "^3.13.1", "eslint-loader": "^1.9.0", "eslint-config-standard": "^10.2.1", "eslint-plugin-html": "^2.0.3", "eslint-plugin-import": "^2.2.0", "eslint-plugin-node": "^4.2.2", "eslint-plugin-promise": "^3.4.0", "eslint-plugin-standard": "^3.0.1", "nodemon": "^1.11.0", "scmp": "^2.0.0" } }

freecodemans

freecodemans posted a new question

koa-template •

运行保错

Module build failed (from ./nodemodules/eslint-loader/index.js): TypeError: Cannot read property 'eslint' of undefined at Object.module.exports (E:\vue\nuxt-learn\nodemodules\eslint-loader\index.js:148:18)

You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.

Leesson

Leesson posted a new question

koa-template •

compile error with [email protected]

There is an error when run dev or build:

ERROR in ./.nuxt/client.js
Module build failed (from ./node_modules/eslint-loader/index.js):
TypeError: Cannot read property 'eslint' of undefined
    at Object.module.exports (/Users/didi/Documents/code/test/nuxtKoaTemplate/node_modules/eslint-loader/index.js:148:18)
 @ multi ./.nuxt/client.js app[0]
✖ fatal Nuxt Build Error
Nuxt Fatal Error :(


It is caused by nuxt2.x and can be resolve by updating the dependecies in package.json:

"dependencies": {
   ...
-  "nuxt": "latest",
+  "nuxt": "^1.4.4",
}


Expect to support the latest version

Benleie

Benleie resolved the question #c35

koa-template •

compile error when dev

so i have to use nuxt@1.4.x to fix it

Benleie

Benleie posted a new question

koa-template •

compile error when dev

After installation,when npm run dev
Error: Plugin/Preset files are not allowed to export objects, only functions.
image

And i updated backpack-core to 0.7.0, but this error still exists.

wen-dong

wen-dong posted a new question

koa-template •

error in ./server/index.js

module build failed: Error: Plugin/Preset files are not allowed to export objects, only function.
In node_modules\backpack-core\babel.js

zgunz42

zgunz42 posted a new question

koa-template •

Failed to Start Dev

After first install the template i got this error

CMD:
yarn dev

OUTPUT

 ERROR  Failed to compile with 1 errors                                                                                                                  11:50:11

 error  in ./server/index.js

Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions. In /home/ubuntu/workspace/node_modules/backpack-core/babel.js
    at createDescriptor (/home/ubuntu/workspace/node_modules/@babel/core/lib/config/config-descriptors.js:178:11)
    at items.map (/home/ubuntu/workspace/node_modules/@babel/core/lib/config/config-descriptors.js:109:50)
    at Array.map (<anonymous>)
    at createDescriptors (/home/ubuntu/workspace/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPresetDescriptors (/home/ubuntu/workspace/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
    at passPerPreset (/home/ubuntu/workspace/node_modules/@babel/core/lib/config/config-descriptors.js:58:96)
    at cachedFunction (/home/ubuntu/workspace/node_modules/@babel/core/lib/config/caching.js:33:19)
    at presets.presets (/home/ubuntu/workspace/node_modules/@babel/core/lib/config/config-descriptors.js:29:84)
    at mergeChainOpts (/home/ubuntu/workspace/node_modules/@babel/core/lib/config/config-chain.js:315:26)
    at /home/ubuntu/workspace/node_modules/@babel/core/lib/config/config-chain.js:278:7

module.js:549
    throw err;
    ^

Error: Cannot find module '/home/ubuntu/workspace/build/main.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
eugeneCN

eugeneCN posted a new question

koa-template •

babel error

`
cd koa-template
npm install
npm run dev

Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/eMule/Desktop/koa-template/node_modules/backpack-core/babel.js
`

mrxu0

mrxu0 posted a new question

koa-template •

Production caused the file directory to change using require error
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/[email protected]@ramda/src/internal/_pipe.js:3:14
    at /Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/[email protected]@ramda/src/internal/_pipe.js:3:27
    at /Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/[email protected]@ramda/src/internal/_arity.js:5:45
    at _map (/Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/[email protected]@ramda/src/internal/_map.js:6:19)
    at map (/Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/[email protected]@ramda/src/map.js:57:14)
    at /Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/[email protected]@ramda/src/internal/_dispatchable.js:39:15
    at /Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/[email protected]@ramda/src/internal/_curry2.js:20:46
    at f1 (/Users/xuyuechao/Work/other-git-project/nuxt-koa/node_modules/[email protected]@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