Openshift部署错误:无法找到模块package.json

时间:2017-09-22 23:49:14

标签: node.js git webpack openshift

我正在尝试通过首先使用webpack捆绑我的节点文件来减小我的openshift后端节点应用程序的大小,然后只需按下它。这是我得到的错误:

Total 642 (delta 200), reused 2 (delta 0)
remote: module.js:471
remote:     throw err;
remote:     ^
remote: 
remote: Error: Cannot find module '/var/lib/openshift/575efb722d5271dec00000f4/app-root/runtime/repo//package.json'
remote:     at Function.Module._resolveFilename (module.js:469:15)
remote:     at Function.Module._load (module.js:417:25)
remote:     at Module.require (module.js:497:17)
remote:     at require (internal/module.js:20:19)
remote:     at [eval]:1:9
remote:     at ContextifyScript.Script.runInThisContext (vm.js:25:33)
remote:     at Object.runInThisContext (vm.js:97:38)
remote:     at Object.<anonymous> ([eval]-wrapper:6:22)
remote:     at Module._compile (module.js:570:32)
remote:     at evalScript (bootstrap_node.js:353:27)
remote: CLIENT_MESSAGE: Stopping Node.js application...
Connection to api-tmarr.rhcloud.com closed by remote host.
fatal: The remote end hung up unexpectedly

这是我的webpack配置文件:

var webpack = require('webpack');
var path = require('path');
var fs = require('fs');

var nodeModules = {};
fs.readdirSync('node_modules')
  .filter(function(x) {
    return ['.bin'].indexOf(x) === -1;
  })
  .forEach(function(mod) {
    nodeModules[mod] = 'commonjs ' + mod;
  });

module.exports = {
  entry: './src/app.js',
  target: 'node',
  output: {
    path: path.join(__dirname, 'build'),
    filename: 'backend.js'
  },
  externals: nodeModules,
  plugins: [
    new webpack.IgnorePlugin(/\.(css|less)$/),

    new webpack.BannerPlugin({banner: 'require("source-map-support").install();', raw: true, entryOnly: false})
  ],
  devtool: 'sourcemap'
}

创建一个backend.js文件,然后将其复制到一个骨架项目中,该项目只有最小的项目,并且使用git连接到openshift。这个新的骨架项目有自己的package.json&amp; start.js文件。

的package.json:

{
  "name": "API",
  "version": "1.0.1",
  "description": "Terry's API Server",
  "private": true,
  "main": "start.js",
  "scripts": {
    "prestart": "NODE_ENV=production",
    "start": "node --use_strict start.js --websocket-port=$OPENSHIFT_NODEJS_PORT --log-level=1"
  },
  "author": "Terry Marr",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.1",
    "express": "~3.4.4",
    "express-cache-ctrl": "^1.0.1"
  },

  "engines": {
    "node": ">= 0.6.0",
    "npm": ">= 1.0.0"
  },
  "devDependencies": {}
}

以下是生成的骨架结构:

/build
  -backend.js
  -backend.js.map
/node_modules ...
/static ...
/utils ...
-.gitignore
-package.json
-start.js

重要的是,我正在尝试做的是REDO我的应用程序。它之前没有webpack工作。也许旧代码有什么东西?对Openshift来说相当新,并且发现文档不是很有帮助。我应该清除我的代码并重新注入吗?不知道该怎么做。感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

更新:没有人回答我的问题,而且Openshift的支持真正被咬了。他们的文件很糟糕,当你被困时,绝对没有人可以提供帮助。我拉了我的(付费)应用程序并转移到Heroku。