简体   繁体   English

ReactJS npm 运行构建引发 elifecycle 和导出错误(奇怪)

[英]ReactJS npm run build throws elifecycle & export errors (weird)

I'm trying to build a React project via npm run build (Creating production build)我正在尝试通过npm run build (创建生产构建)构建一个 React 项目

  • I can use npm start just fine and it compiles the react code and works perfectly on the browser我可以使用npm start就好了,它编译反应代码并在浏览器上完美运行

npm run build - error npm 运行构建错误

It's weird since Initially I was only getting the ELIFECYCLE error, then I tried to clear the npm-cache along with deleting the node_modules directory and package-lock.json to reinstall everything fresh.这很奇怪,因为最初我只收到 ELIFECYCLE 错误,然后我尝试清除 npm-cache 并删除 node_modules 目录和 package-lock.json 以重新安装所有内容。

npm cache clean --force
delete node_modules folder
delete package-lock.json file
npm install

elifecycle error stackoverflow post elifecycle 错误stackoverflow 帖子

Now that i've done that, the npm start command still compiles & runs the react frontend just fine, however when I try to build it, I'm getting this export error aswell, it's weird since this isn't an issue现在我已经这样做了, npm start命令仍然可以编译并运行反应前端就好了,但是当我尝试构建它时,我也收到了这个导出错误,这很奇怪,因为这不是问题

CheckBoard.js Component: 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 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

I can't figure out why react run build is acting so odd, even after I fully reinitialized npm and the export clearly works on development builds and works, I dont know what the issue is with the build.我无法弄清楚为什么 react run build 表现得如此奇怪,即使在我完全重新初始化 npm 并且导出显然适用于开发构建和工作之后,我不知道构建的问题是什么。

Package-lock.json: Github -> Frontend/package-lock.json (It's very long, that's why I cant copy/paste it onto here) Package-lock.json: Github -> Frontend/package-lock.json (它很长,所以我不能复制/粘贴到这里)

Thanks to shidoro I solved this, I changed the感谢shidoro我解决了这个问题,我改变了

module.exports = {
    checkBoard
} 

to the ES6 way:以 ES6 方式:

export{ checkBoard }

And it compiled (with warnings, but that's due to some lack of error handling)它编译(带有警告,但这是由于缺乏错误处理)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM