使用浏览器同步/ nodejs部署到heroku“无法打开浏览器”

时间:2018-12-01 23:32:59

标签: node.js heroku browser-sync

我继承了一个相当简单的代码库,试图将其部署到heroku

这是 package.json 文件的一部分:

...

"engines": {
    "node": "8.1.1",
    "npm": "5.0.3"
  },
  "scripts": {
    "clean": "rimraf dist/{css/*,js/*,images/*}",
    "autoprefixer": "postcss -u autoprefixer -r dist/css/*",
    "scss": "node-sass --output-style compressed -o dist/css src/scss",
    "lint": "eslint src/js || true",
    "lint-scss": "stylelint src/scss/*.scss --syntax scss || true",
    "uglify": "mkdirp dist/js -p && uglifyjs src/js/*.js -m -c -o dist/js/main.min.js",
    "imagemin": "imagemin src/images/* -o dist/images",
    "serve": "browser-sync start --server --files \"dist/css/*.css, dist/js/*.js, **/*.html, !node_modules/**/*.html\"",
    "build:css": "run-s lint-scss scss autoprefixer",
    "build:js": "run-s lint uglify",
    "build:images": "run-s imagemin",
    "build": "run-s build:*",
    "watch:css": "onchange \"src/scss\" -- run-s build:css",
    "watch:js": "onchange \"src/js\" -- run-s build:js",
    "watch:images": "onchange \"src/images\" -- run-s build:images",
    "watch": "run-p serve watch:*",
    "postinstall": "run-s build watch"
  },
  "devDependencies": {
    "autoprefixer": "^9.0.1",
    "browser-sync": "^2.26.3",
    "eslint": "^5.2.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-node": "^7.0.1",
    "eslint-plugin-promise": "^3.8.0",
    "eslint-plugin-standard": "^3.1.0",
    "imagemin-cli": "^3.0.0",
    "mkdirp": "^0.5.1",
    "node-sass": "^4.9.2",
    "npm-run-all": "^4.1.3",
    "onchange": "^4.1.0",
    "postcss-cli": "^6.0.0",
    "rimraf": "^2.5.4",
    "stylelint": "^9.4.0",
    "uglify-es": "^3.3.10"
  },
  "main": ".eslintrc.js"
}

和我的 Procfile

web: npm run serve

但是当我部署到heroku时-构建失败并挂起:

remote:        [Browsersync] Access URLs:
remote:         ---------------------------------------
remote:               Local: http://localhost:3000
remote:            External: http://172.16.113.170:3000
remote:         ---------------------------------------
remote:                  UI: http://localhost:3001
remote:         UI External: http://localhost:3001
remote:         ---------------------------------------
remote:        [Browsersync] Serving files from: ./
remote:        [Browsersync] Watching files...
remote:        [Browsersync] Couldn't open browser (if you are using BrowserSync in a headless environment, you might want to set the open option to false)

如有需要,我可以提供更多详细信息。

1 个答案:

答案 0 :(得分:1)

我有相同的问题要解决:

  1. 从package.json中删除<ScrollView android:id="@+id/scrollView2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/button" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_marginTop="8dp" android:layout_marginBottom="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toTopOf="parent" tools:layout_editor_absoluteX="0dp"> <TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/button" android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:gravity="center" android:text="Coordinates: " android:textSize="30sp" /> </ScrollView> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_marginStart="8dp" android:layout_marginLeft="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginRight="8dp" android:layout_marginBottom="8dp" android:text="Request Location" app:layout_constraintBottom_toTopOf="@+id/scrollView2" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout>
  2. 通过添加"postinstall": "run-s build watch"来修改服务脚本。它应该看起来像这样 --port $PORT
  3. 在文件夹的根目录上创建一个Procfile。 在Procfile中包括以下内容:"serve": "browser-sync start --server --files --port $PORT \"dist/css/*.css, dist/js/*.js, **/*.html, !node_modules/**/*.html\"",
  4. 您可以通过命令web: npm run build watch在本地运行heroku应用,也可以只部署它即可使用。