Zeit / pkg: не удается найти модуль 'config' - PullRequest
0 голосов
/ 24 апреля 2018

Я разобрал эту проблему до простого теста. Я использую модуль «config» для определения значений конфигурации для моего приложения. Pkg не жалуется на сборку, но barfs во время выполнения со следующим сообщением. Я что-то упустил?

jim-macbookpro:~/development/node/pkgtest$ ./pkgtest-macos
pkg/prelude/bootstrap.js:1172
      throw error;
      ^

Error: Cannot find module 'config'
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
    at Function.Module._resolveFilename (module.js:540:15)
    at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1269:46)
    at Function.Module._load (module.js:470:25)
    at Module.require (module.js:583:17)
    at Module.require (pkg/prelude/bootstrap.js:1153:31)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/snapshot/pkgtest/index.js:1:78)
    at Module._compile (pkg/prelude/bootstrap.js:1243:22)
    at Object.Module._extensions..js (module.js:650:10)
    at Module.load (module.js:558:32)

index.js прост:

const config = require('config');
console.log('yo:', config.message);

и у меня есть default.json в локальной директории config:

{
    "message": "whodapunk?"
}

Мой package.json, за что он стоит:

{
    "name": "pkgtest",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "author": "",
    "license": "ISC",
    "dependencies": {
        "config": "^1.30.0"
    },
    "bin": "index.js"
}

1 Ответ

0 голосов
/ 27 августа 2018

У меня была та же проблема, и это было потому, что мой конфигурационный файл был добавлен в .gitignore - как только я удалил его оттуда, он заработал как шарм!

...