0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

now v2でのtextlint読み込みエラー 2019/04 現在

Posted at
now-textlint-test$ ll
index.js
node_modules/
now.json
package-lock.json
package.json
package.json
{
  "name": "now-textlint-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "textlint": "^11.2.3"
  }
}
now.json
{
  "version": 2,
  "name": "now-textlint-test",
  "builds": [{
    "src":"index.js", "use":"@now/node", "config": { "maxLambdaSize": "40mb" }
  }],
  "alias":"texttest.now.sh"
}
index.js
const { parse } = require('url')

module.exports = (req, res) => {
  const { query } = parse(req.url, true)
  const { name = 'World' } = query

//const pkgConf = require("read-pkg-up");
//console.log(pkgConf.sync({ cwd: __dirname }))


  const TextLintEngine = require('textlint').TextLintEngine;
  const engine = new TextLintEngine();

  res.end(`Hello ${name}! ${__dirname}`)
}

単純なサンプルにtextlintの読み込みを加えたもの。

アクセス結果のログが(now log)

2019-04-29T21:46:51.508Z  TypeError: Cannot read property 'version' of undefined
                              at Config.get [as hash] (/var/tmp/1daede63/node_modules/textlint/lib/textlint/src/config/config.js:295:56)
                              at new CacheBacker (/var/task/index.js:19028:36)
                              at TextLintEngine.AbstractTextLintEngine (/var/task/index.js:44961:26)
                              at new TextLintEngine (/var/task/index.js:33699:47)
                              at Server.module.exports.module.exports (/var/task/index.js:5626:18)
                              at emitTwo (events.js:126:13)
                              at Server.emit (events.js:214:7)
                              at parserOnIncoming (_http_server.js:619:12)
                              at HTTPParser.parserOnHeadersComplete (_http_common.js:115:23)


関係ないが、このエラーによりレスポンスは

502: An error occurred with your deployment

Code: NO_STATUS_CODE_FROM_LAMBDA (more)

に。

    get hash() {
        const pkgConf = require("read-pkg-up");
        const version = pkgConf.sync({ cwd: __dirname }).pkg.version;
        const toString = JSON.stringify(this.toJSON());
        return md5(`${version}-${toString}`);
}

https://github.com/textlint/textlint/blob/85edfd90f9df0496adb6ed9552b7963dfd12fedb/packages/textlint/src/config/config.ts#L238-L242

ここかな?ローカルのjsならば

    Object.defineProperty(Config.prototype, "hash", {
        /**
         * Return hash string of the config and textlint version
         * @returns {string}
         */
        get: function () {
            var pkgConf = require("read-pkg-up");
            var version = pkgConf.sync({ cwd: __dirname }).pkg.version;
            var toString = JSON.stringify(this.toJSON());
            return md5(version + "-" + toString);
        },
        enumerable: true,
        configurable: true
    });

index.jsでは__dirnameは参照できるし、console.log(pkgConf.sync({ cwd: __dirname }))は自作のrootのpackage.jsonの内容が出力されるので、
ビルドの問題か不明。

now側でyarnを使ったbuildをせずにローカルのnode_modulesをアップロードできないか調べてみたが、うまくヒットしない。

昔はwebpack時点でのエラーだった記憶があるので、これもnow側のバージョンアップでまた変化があるかな。


去年試したときは今回とは別のエラーだった気がするが記録がないので、今回はまた半年後ぐらいに再挑戦するときの参照情報として残しておく。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?