在Docker中运行Gatsby时出现“未定义错误'___ emitter'”

时间:2019-06-25 15:53:35

标签: javascript node.js docker gatsby

尝试在Docker容器中运行Gatsby网站时遇到问题。当我执行gatsby develop时,最终出现以下错误:

ERROR  Failed to compile with 3 errors15:31:59
⠀
 error  in /.cache/json-store.js
⠀
Module Error (from /node_modules/eslint-loader/index.js):

/.cache/json-store.js
  48:5  error  '___emitter' is not defined  no-undef
  53:5  error  '___emitter' is not defined  no-undef

✖ 2 problems (2 errors, 0 warnings)


 @ /.cache/root.js 19:0-37 68:31-40 77:38-47 84:27-36
 @ /.cache/app.js
 @ multi /node_modules/event-source-polyfill/src/eventsource.js
⠀
 error  in /.cache/socketIo.js
⠀
Module Error (from /node_modules/eslint-loader/index.js):

/.cache/socketIo.js
  56:13  error  '___emitter' is not defined  no-undef

✖ 1 problem (1 error, 0 warnings)


 @ /.cache/app.js 14:0-34 25:15-23
 @ multi /node_modules/event-source-polyfill/src/eventsource.js
⠀
 error  in /.cache/loader.js
⠀
Module build failed (from /node_modules/eslint-loader/index.js):
TypeError: Cannot read property 'type' of null
Occurred while linting /cache/loader.js:30
    at Object.VariableDeclarator
(/node_modules/eslint-plugin-react/lib/util/usedPropTypes.js:464:21)
    at updatedRuleInstructions.(anonymous function)
(/node_modules/eslint-plugin-react/lib/util/Components.js:780:47)
    at listeners.(anonymous function).forEach.listener
(/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector
(/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors
(/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (/node_modules/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode
(/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:632:23)
    at nodeQueue.forEach.traversalInfo (/node_modules/eslint/lib/linter.js:752:32)

 @ /.cache/app.js 17:0-57 21:0-21 50:2-8 51:2-8 52:15-21 52:50-56 52:80-86
 @ multi /node_modules/event-source-polyfill/src/eventsource.js
⠀
✖ 「wdm」:
ERROR in /.cache/json-store.js
Module Error (from /node_modules/eslint-loader/index.js):

/.cache/json-store.js
  48:5  error  '___emitter' is not defined  no-undef
  53:5  error  '___emitter' is not defined  no-undef

✖ 2 problems (2 errors, 0 warnings)

 @ /.cache/root.js 19:0-37 68:31-40 77:38-47 84:27-36
 @ /.cache/app.js
 @ multi /node_modules/event-source-polyfill/src/eventsource.js
(webpack)-hot-middleware/client.js?path=/__webpack_hmr&reload=true&overlay=false /.cache/app

ERROR in /.cache/socketIo.js
Module Error (from /node_modules/eslint-loader/index.js):

/.cache/socketIo.js
  56:13  error  '___emitter' is not defined  no-undef

✖ 1 problem (1 error, 0 warnings)

 @ /.cache/app.js 14:0-34 25:15-23
 @ multi /node_modules/event-source-polyfill/src/eventsource.js
(webpack)-hot-middleware/client.js?path=/__webpack_hmr&reload=true&overlay=false /.cache/app

ERROR in /.cache/loader.js
Module build failed (from /node_modules/eslint-loader/index.js):
TypeError: Cannot read property 'type' of null
Occurred while linting /cache/loader.js:30
    at Object.VariableDeclarator
(/node_modules/eslint-plugin-react/lib/util/usedPropTypes.js:464:21)
    at updatedRuleInstructions.(anonymous function)
(/node_modules/eslint-plugin-react/lib/util/Components.js:780:47)
    at listeners.(anonymous function).forEach.listener
(/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector
(/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors
(/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (/node_modules/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode
(/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:632:23)
    at nodeQueue.forEach.traversalInfo (/node_modules/eslint/lib/linter.js:752:32)
ℹ 「wdm」: Failed to compile.

考虑到它可能是由我项目的任何细节引起的,所以我使用Gatsby默认启动器启动了一个新项目,起初出现以下错误:

error Error in "/node_modules/gatsby-transformer-sharp/gatsby-node.js":


  Error: 'linux-x64' binaries cannot be used on the 'linuxmusl-x64' platform. Pl  ease remove the 
'node_modules/sharp/vendor' directory and run 'npm install'.

我删除了node_modules(以为本地环境的依赖关系与Docker容器的依赖关系可能不兼容),然后再次尝试,这时我遇到了与以前相同的错误。

这些是我的package.json

{
  "name": "gatsby-starter-default",
  "private": true,
  "description": "A simple starter to get up and developing quickly with Gatsby",
  "version": "0.1.0",
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
  "dependencies": {
    "gatsby": "^2.10.4",
    "gatsby-image": "^2.2.3",
    "gatsby-plugin-manifest": "^2.2.0",
    "gatsby-plugin-offline": "^2.2.0",
    "gatsby-plugin-react-helmet": "^3.1.0",
    "gatsby-plugin-sharp": "^2.2.1",
    "gatsby-source-filesystem": "^2.1.0",
    "gatsby-transformer-sharp": "^2.2.0",
    "prop-types": "^15.7.2",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-helmet": "^5.2.1"
  },
  "devDependencies": {
    "prettier": "^1.18.2"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "MIT",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write src/**/*.{js,jsx}",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\""
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-default"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}

和我的Dockerfile(尽管我在稍作改动后也遇到了相同的问题):

FROM node:alpine

# Also exposing VSCode debug ports
EXPOSE 8000 9929 9230

RUN apk add --no-cache python make g++ \
 && apk add vips-dev fftw-dev build-base \
        --update-cache \
        --repository https://alpine.global.ssl.fastly.net/alpine/edge/community \
        --repository https://alpine.global.ssl.fastly.net/alpine/edge/main \
 && rm -fR /var/cache/apk/*


RUN npm install -g gatsby-cli yarn

WORKDIR .
COPY ./package.json .
RUN yarn install && yarn cache clean
COPY . .
ENTRYPOINT yarn install && gatsby develop -H 0.0.0.0

问题似乎与依赖关系有关,但是我在克隆了一个盖茨比启动程序之后也弄对了,所以我认为它们一定是正确的。此外,如果我直接在本地系统上(没有Docker)执行该项目,则该项目将运行得很好,是否可能是node映像与Gatsby依赖项之间的不兼容?

在此先感谢您的帮助!

0 个答案:

没有答案