Ошибка: инвариант не удалось: Ha sh истории требуется DOM - PullRequest
0 голосов
/ 07 мая 2020

Во-первых, прошу прощения за мой бедный английский sh, wi sh вы понимаете ...

здесь отображается ошибка:

ERROR in   Error: webpack-internal:///./node_modules/tiny-invariant/dist/tiny-invariant.esm.js:14
    throw new Error(prefix + ": " + (message || ''));
    ^
  Error: Invariant failed: Hash history needs a DOM

  - tiny-invariant.esm.js:14 invariant
    [.]/[tiny-invariant]/dist/tiny-invariant.esm.js:14:9

  - history.js:577 createHashHistory
    [.]/[history]/cjs/history.js:577:16

  - index.js:36 _default
    [.]/[dva]/lib/index.js:36:64

  - index.js:32 eval
    webpack-internal:///./src/index.js:32:53

  - index.html:7396 Module../src/index.js
    /Users/mac/Desktop/workspace/test/reproduce/code-reproduce/src/index.html:7396:1

  - index.html:21 __webpack_require__
    /Users/mac/Desktop/workspace/test/reproduce/code-reproduce/src/index.html:21:30

  - index.html:3 eval
    [.]/[html-webpack-plugin]/lib/loader.js!./src/index.html:3:34

  - index.html:5904 Object../node_modules/html-webpack-plugin/lib/loader.js!./src/index.html
    /Users/mac/Desktop/workspace/test/reproduce/code-reproduce/src/index.html:5904:1

  - index.html:21 __webpack_require__
    /Users/mac/Desktop/workspace/test/reproduce/code-reproduce/src/index.html:21:30

  - index.html:85
    /Users/mac/Desktop/workspace/test/reproduce/code-reproduce/src/index.html:85:18

Теоретически проект выполняется в моем локальный сервер, у него должен быть дом.

Это мой минимальный воспроизводимый адрес репозитория:

https://github.com/shauvet/code-reproduce/tree/dva-admin

шаги:

шаг 1: пряжа, шаг 2: начало пряжи

import './index.html'
import 'babel-polyfill'
import dva from 'dva'
import createLoading from 'dva-loading'
import { hashHistory } from 'dva/router'
import appMod from './models'
import router from './router'

// 1. Initialize
const app = dva()

app.use(createLoading())

// 2. Model
// app.model(require('./models/app'))
app.model(appMod)
// 3. Router
// app.router(require('./router'))
app.router(router)

// 4. Start
app.start('#root')

информация о среде:

версия узла: 12.16.2 версия ОС: osx 10.15.4

1 Ответ

1 голос
/ 10 мая 2020

Наконец, я добавил в webpackHtmlPlugin :

new HtmlWebpackPlugin({
      // filename: 'index.html',
      template: 'src/index.html',
      inject: 'body'  // here
})

И ошибка исчезла.

...