[英]ReactJS npm run build throws elifecycle & export errors (weird)
我正在嘗試通過npm run build
(創建生產構建)構建一個 React 項目
npm start
就好了,它編譯反應代碼並在瀏覽器上完美運行這很奇怪,因為最初我只收到 ELIFECYCLE 錯誤,然后我嘗試清除 npm-cache 並刪除 node_modules 目錄和 package-lock.json 以重新安裝所有內容。
npm cache clean --force
delete node_modules folder
delete package-lock.json file
npm install
elifecycle 錯誤stackoverflow 帖子
現在我已經這樣做了, npm start
命令仍然可以編譯並運行反應前端就好了,但是當我嘗試構建它時,我也收到了這個導出錯誤,這很奇怪,因為這不是問題
CheckBoard.js 組件:
...
import { checkBoard } from './validation/checker_validation'
//import checker_validation from './validation/checker_validation'
//import { checker_validation } from './validation/checker_validation'
import { tokenChars } from 'ws/lib/validation'
import { parse } from 'uuid'
export default class CheckerBoard extends Component {
state = {
gameBoard: this.props.gameData,
boardInv : this.props.boardInv,
dispOverlay : {},
selectedPawn : null,
selectedValid : []
}
//Overlay Initializer:
//Whenever a pawn is clicked, this function executes:
//This function executes the validation algorithm, then generates an overlay of all possible moves the user can make
pawnClick = async (e) => {
const coord1D = parseInt((e.target.id).split('-')[1]);
await this.setState({dispOverlay: {'selectedPawn' : coord1D} });
const newGame = [...(this.state.gameBoard.map((e)=> {return parseInt(e)}))]
console.log('PAWN CLICK DEBUG:');
console.log('Game Board:');
console.log(newGame);
console.log('Coord 1D');
console.log(coord1D);
let valid = this.state.boardInv ? checkBoard(newGame.reverse(),63-coord1D) : checkBoard(newGame, coord1D);
if(this.state.boardInv){
valid = [...valid.map((e) => {return e.map( (j) => {return -1*j} ) })];
}
this.setState({
selectedValid : valid
})
console.log('Validated: '+JSON.stringify(valid))
const reducerSum = (pV, cV) => pV + cV;
for(let v of valid){
let entry = this.state.dispOverlay;
if(Math.abs(v[0]) < 14){
entry[parseInt(coord1D)+parseInt(v)] = false; //false is move, true is kill
} else {
for(let [i,e] of v.entries()){
const killEntry = parseInt(coord1D)+v.slice(0,i+1).reduce(reducerSum,0);
entry[killEntry] = true
}
//Returns the possible positions of selected Pawn (for every possibility)
//entry[parseInt(coord1D)+parseInt(v)] = true;
}
this.setState({dispOverlay : entry});
}
}
...
checker_validation.js
const checkBoard = (board, pawnCoord, justKilled) => {
...algorithm that returns something...
if(!foundKill){
return [[]];
}
return res;
}
// console.log(checkBoard(gameboard,42))
module.exports = {
checkBoard
}
//exported here
我無法弄清楚為什么 react run build 表現得如此奇怪,即使在我完全重新初始化 npm 並且導出顯然適用於開發構建和工作之后,我不知道構建的問題是什么。
Package-lock.json: Github -> Frontend/package-lock.json (它很長,所以我不能復制/粘貼到這里)
感謝shidoro我解決了這個問題,我改變了
module.exports = {
checkBoard
}
以 ES6 方式:
export{ checkBoard }
它編譯(帶有警告,但這是由於缺乏錯誤處理)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.