【问题标题】:Module build failed (from ./node_modules/html-loader/dist/cjs.js):模块构建失败(来自 ./node_modules/html-loader/dist/cjs.js):
【发布时间】:2020-07-03 04:39:56
【问题描述】:

我正在尝试快速启动 ava electron webpack 和三个,但在该过程中出现了问题。

这里是项目的存储库:

https://github.com/etiennerin/ecsy-three-electron-ava-quick-start

通过键入npm run dev 尝试使用我的项目,我收到以下错误消息:

我正在使用 Windows。

我认为这个错误可能与我的 webpack 配置有关,在我尝试了一些 npm-update 之前,它似乎可以正常工作:

'use strict'

import { app, BrowserWindow } from 'electron'
import * as path from 'path'
import { format as formatUrl } from 'url'
import * as THREE from '../../node_modules/three/build/three.module.js';
//import {World} from '../../node_modules/ecsy/build/ecsy.module.js';

const isDevelopment = process.env.NODE_ENV !== 'production'

// global reference to mainWindow (necessary to prevent window from being garbage collected)
let mainWindow

function createMainWindow() {
  const window = new BrowserWindow({webPreferences: {nodeIntegration: true}})

  if (isDevelopment) {
    window.webContents.openDevTools()
  }

  if (isDevelopment) {
    window.loadURL(`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`)
  }
  else {
    window.loadURL(formatUrl({
      pathname: path.join(__dirname, 'index.html'),
      protocol: 'file',
      slashes: true
    }))
  }

  window.on('closed', () => {
    mainWindow = null
  })

  window.webContents.on('devtools-opened', () => {
    window.focus()
    setImmediate(() => {
      window.focus()
    })
  })

  return window
}

// quit application when all windows are closed
app.on('window-all-closed', () => {
  // on macOS it is common for applications to stay open until the user explicitly quits
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', () => {
  // on macOS it is common to re-create a window even after all windows have been closed
  if (mainWindow === null) {
    mainWindow = createMainWindow()
  }
})

// create main BrowserWindow when electron is ready
app.on('ready', () => {
  mainWindow = createMainWindow()
})

还有我最新的 package.json:

{
  "name": "electron-webpack-quick-start",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "start": "electron-webpack dev",
    "dev": "electron-webpack dev",
    "compile": "electron-webpack",
    "dist": "yarn compile && electron-builder",
    "dist:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null",
    "test": "ava"
  },
  "dependencies": {
    "source-map-support": "^0.5.16"
  },
  "ava": {
    "files": [
      "spec/**/*"
    ],
    "require": [
      "esm"
    ]
  },
  "devDependencies": {
    "ava": "^3.5.1",
    "ecsy": "^0.2.3",
    "electron": "8.1.1",
    "electron-builder": "^22.4.1",
    "electron-webpack": "^2.7.4",
    "esm": "^3.2.25",
    "html-loader": "^1.0.0",
    "three": "^0.112.1",
    "webpack": "^4.42.0"
  }
}

非常感谢您的每一条建议!

【问题讨论】:

    标签: node.js npm webpack electron


    【解决方案1】:

    您是否尝试过清理并重新安装

    rm -rf node_modules yarn.lock package-lock.json
    npm install // or yarn
    run webpack
    

    【讨论】:

    • 感谢您的帮助,是的,我做到了,但不幸的是它没有解决我的问题,我也再次从 github 中提取了它(没有所有 dist、package-lock、node-modules 文件,结果相同) 我不知道这是否会改变任何东西,但我使用的是 electron-webpack,但它仍然像往常一样使用 webpack。
    • 最有可能检查你的 package.json 版本。如果您使用 * 或 ^。它会随着时间而更新。尝试与 package-lock.json 匹配。并修复 package.json 中的版本
    • 再次感谢,但我仍然无法找出问题所在,我刚刚在我的 git 上恢复了几个版本,但这包含 2 个安全警报要考虑,我什至查看了所有最新版本npm 网站并没有找到可行的解决方案
    【解决方案2】:

    我也遇到了同样的问题,但是我通过查看.lock文件解决了,html-loader现在是v1.0.0[2020.3.19更新!],请注意这是一个完全重写的加载器,它是不是基于html-loader-v1.0.0-alpha,所以你需要 将 "html-loader": "1.0.0-alpha.0" 添加到 package.json 文件中的“devDependencies”中。

    第二次你应该运行这个命令rm -rf node_module && rm -rf yarn.lock && yarn install

    更多详情请查看this link

    【讨论】:

    • 谢谢,它确实有效,但是一旦我输入 npm run audit fix 它就会停止工作,因为有两个主要的安全问题和 1 个中等问题,我正试图摆脱它。跨度>
    【解决方案3】:
    1. 从 packages.json 中删除 expose-loader

    2. 从 .lock 和模块中删除

    rm -rf node_modules yarn.lock

    1. 然后重新安装依赖项减去暴露加载程序

    yarn install

    1. 问题来自暴露加载程序,请更改配置中的

    config/webpack/environment

    
    const webpack = require("webpack")
    environment.plugins.append("Provide", new webpack.ProvidePlugin({
    
      $: 'jquery',
      
      jQuery: 'jquery',
      
      Popper: ['popper.js', 'default']
      
      }))
    
    

    这应该适用于rails 6

    【讨论】:

      猜你喜欢
      • 2020-08-14
      • 2021-03-05
      • 2022-10-22
      • 2021-10-31
      • 2020-09-01
      • 2022-09-30
      • 2021-07-01
      • 2022-12-13
      • 2020-01-12
      相关资源
      最近更新 更多