【问题标题】:Error was not caught TypeError: Cannot use 'in' operator to search for 'electron' in undefined at next-dev.js:8未捕获错误类型错误:无法使用“in”运算符在 next-dev.js:8 的未定义中搜索“电子”
【发布时间】:2020-11-14 09:18:10
【问题描述】:

我在尝试以开发模式运行 next.js 时遇到此错误。我不知道为什么会发生这种情况,因为我什至没有在这个应用程序中使用电子。

Error was not caught TypeError: Cannot use 'in' operator to search for 'electron' in undefined at next-dev.js:8

这是我的下一个.config

const withTM = require('next-transpile-modules')(['@my-storybook'])
const watchStorybook = require('@my-storybook/watch-storybook');
const webpack = require('webpack');
const ENV = require('./config/environments/environment')

let GPA_ENV;

switch (process.env.API_URL_BASE) {
  case 'https://my-api':
    GPA_ENV = 'k15'
    break;
  case 'https://my-api2':
    GPA_ENV = 'development'
    break;
  default:
    GPA_ENV = 'homolog'
}

module.exports = withTM({
  webpack: (config, { dev }) => {
    if(dev) watchStorybook();

    config.plugins.push(
      new webpack.DefinePlugin({
        process: {
          env: {
            GPA_ENV : JSON.stringify(GPA_ENV)
          }
        }
      })
    )

    return config
  },
  publicRuntimeConfig: {
    API_URL_BASE: process.env.API_URL_BASE || ENV.URLS.API_URL_BASE || 'https://my-api3',
    IMAGE_URL_BASE: process.env.IMAGE_URL_BASE || ENV.URLS.IMAGE_URL_BASE || 'https://my-api',
    STOMP_URL_BASE: process.env.STOMP_URL_BASE || 'https://my-websocket',
    STOMP_RECONNECT_DELAY: process.env.STOMP_RECONNECT_DELAY || '10000',
    SECURE_COOKIES: process.env.SECURE_COOKIES || '0',
    ROBOTS_NOINDEX: process.env.ROBOTS_NOINDEX || '0',
    SITE_URL_BASE: process.env.SITE_URL_BASE || 'https://my-api',
    GPA_ENV: GPA_ENV,
    USE_INTELIPOST: !!Number(process.env.USE_INTELIPOST),
  },
})

这是我的 package.json

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "create-component": "node config/scripts/create-component",
    "create-page": "node config/scripts/create-page",
    "pa:dev": "npm run env:pa:dev && npm run dev",
    "pa:hlg": "npm run env:pa:hlg && npm run dev",
    "adega:dev": "npm run env:adega:dev && npm run dev",
    "adega:hlg": "npm run env:adega:hlg && npm run dev",
    "adega:stage": "npm run env:adega:stage && npm run dev",
    "ex:dev": "npm run env:ex:dev && npm run dev",
    "ex:hlg": "npm run env:ex:hlg && npm run dev",
    "env:pa:dev": "node ./node_modules/app-json-env-gen/cli.js dir=./__env__/pa target=dev output=./config/environments/environment.js",
    "env:adega:dev": "node ./node_modules/app-json-env-gen/cli.js dir=./__env__/adega target=dev output=./config/environments/environment.js",
    "env:ex:dev": "node ./node_modules/app-json-env-gen/cli.js dir=./__env__/ex target=dev output=./config/environments/environment.js",
    "env:pa:hlg": "node ./node_modules/app-json-env-gen/cli.js dir=./__env__/pa target=hlg output=./config/environments/environment.js",
    "env:adega:hlg": "node ./node_modules/app-json-env-gen/cli.js dir=./__env__/adega target=hlg output=./config/environments/environment.js",
    "env:ex:hlg": "node ./node_modules/app-json-env-gen/cli.js dir=./__env__/ex target=hlg output=./config/environments/environment.js",
    "env:pa:prd": "node ./node_modules/app-json-env-gen/cli.js dir=./__env__/pa target=prd output=./config/environments/environment.js",
    "env:adega:prod": "node ./node_modules/app-json-env-gen/cli.js dir=./__env__/adega target=prd output=./config/environments/environment.js",
    "env:adega:stage": "node ./node_modules/app-json-env-gen/cli.js dir=./__env__/adega target=prd output=./config/environments/environment.js",
    "env:ex:prd": "node ./node_modules/app-json-env-gen/cli.js dir=./__env__/ex target=prd output=./config/environments/environment.js"
  },
  "dependencies": {
    "@my-storybook": "1.0.1-7",
    "@material-ui/core": "^4.9.13",
    "@material-ui/icons": "^4.9.1",
    "@material-ui/styles": "^4.9.13",
    "@zeit/next-sass": "^1.0.1",
    "next": "9.3.6",
    "next-transpile-modules": "^3.3.0",
    "node-sass": "^4.14.0",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "redux-saga": "^1.1.3",
    "webpack": "^4.43.0"
  },
  "devDependencies": {
    "@types/node": "^13.13.4",
    "@types/react": "^16.9.34",
    "app-json-env-gen": "^0.6.0",
    "tslint": "6.1.2",
    "tslint-config-airbnb": "5.11.2",
    "tslint-react": "5.0.0",
    "typescript": "^3.8.3"
  }
}

我尝试过: 删除 node_modules 和 package-lock,但没有成功。 在我的应用中搜索electron,但是没有这个词,只有在next.js node_modules文件中。

我不知道我还能做什么。

任何人都可以对此有所了解吗?谢谢大家,你们太棒了!

【问题讨论】:

  • 可能与您的 package.json 或配置文件无关。它与您正在做的事情有关,可能是搜索、映射或过滤某处?
  • 对我来说,这个错误是在将 dotenv-webpack 从 2.0.0 升级到 3.0.0 后开始发生的。我已经记录了该插件的问题:github.com/mrsteele/dotenv-webpack/issues/238
  • @EvHaus,上帝保佑你。你应该得到一枚奖牌

标签: webpack electron next.js


【解决方案1】:

我没有试图理解为什么会发生,但可以通过简单地添加来修复它

if (typeof process.versions === 'undefined') process.versions = {};

到您的/pages/_app.js 文件。

【讨论】:

    猜你喜欢
    • 2013-06-15
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-25
    • 1970-01-01
    • 2014-07-15
    • 2013-09-01
    • 1970-01-01
    相关资源
    最近更新 更多