找不到模块“集群”

时间:2019-08-31 14:17:03

标签: javascript node.js

我正在设置food2fork API请求,但出现此错误 “找不到模块:错误:无法解析“我的项目路径”中的“集群”

我尝试重新安装webpack,npm,删除modules文件夹并在之后重新安装npm,错误是相同的。

未捕获的错误:找不到模块“集群”

at webpackMissingModule (index.js:13)
at eval (index.js:13)
at Object../src/js/index.js (bundle.js:4775)
at __webpack_require__ (bundle.js:20)
at eval (webpack:///multi_(:8080/webpack)-dev-server/client?:3:18)
at Object.0 (bundle.js:4822)
at __webpack_require__ (bundle.js:20)
at bundle.js:84
at bundle.js:87

我在控制台和源面板中得到了这样的信息:

var _cluster = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module 'cluster'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()));

在CMD终端中,我尝试独立安装集群,并进行了安装,但是终端警告为: “ webpack-cluster@3.2.0需要一个webpack@1.x的同位体,但未安装。 您必须自己安装对等依赖项; 这是我的依赖项:

"dependencies": {
    "axios": "^0.19.0",
    "babel-core": "^6.26.3",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "fsevents": "^1.2.9",
    "html-webpack-plugin": "^3.2.0",
    "jquery": "^3.4.1",
    "webpack-dev-server": "^3.8.0"
  },
  "devDependencies": {
    "@babel/core": "^7.5.5",
    "@babel/preset-env": "^7.5.5",
    "babel-loader": "^7.1.5",
    "npm-install-webpack-plugin": "^4.0.5",
    "webpack": "^4.39.3",
    "webpack-cli": "^3.3.7",
    "webpack-cluster": "^3.2.0"

有什么建议吗?

这是js文件中的代码: index.js:

    import Search from './models/Search';
    import * as searchView from './views/searchView';
    import {elements} from './views/base';
    import { setMaxListeners } from 'cluster';
    const state = {}
    const controlSearch = async () => {
        // 1) Get query from view 
        const query = searchView.getInput();

        if (query) {
            // 2) New search object and add to state
            state.search = new Search(query);
            // 3) Prepare UI for results

            // 4) Search for recipes
            await state.search.getResults();
            // 5) render results on UI
            searchView.renderResults(state.search.result);
        }
    }

        elements.searchForm.addEventListener('submit', e => {
            e.preventDefault();
            controlSearch();
        })

Search.js:

   import axios from 'axios';
    export default class Search {
        constructor(query) {
            this.query = query;
        }
         async getResults() {
            const proxy = 'https://cors-anywhere.herokuapp.com/'
            const key = '6747b75e8bbd788a46776afdf9f0c7a6'
            try {
                const res = await axios(`${proxy}https://www.food2fork.com/api/search?key=${key}&q=${this.query}`);
                this.result = res.data.recipes;
                //console.log(this.result);
            } catch(error){
                alert(error);
            }
        }
    }

searhView.js:

 import {elements} from './base';
    export  const getInput = () => elements.searchInput.value;


    const renderRecipe = recipe => {
        const markup = `
        <li>
        <a class="results__link" href="#${recipe.recipe_id}">
            <figure class="results__fig">
                <img src="${recipe.image_url}" alt="${recipe.title}">
            </figure>
            <div class="results__data">
                <h4 class="results__name">${recipe.title}</h4>
                <p class="results__author">${recipe.publisher}</p>
            </div>
        </a>
    </li>
        `;
        elements.searchResList.insertAdjacentHTML('beforeend', markup); 


    };
    export const renderResults = recipes => {

        recipes.forEach(renderRecipe);
    };

以及来自base.js :(仅DOM元素变量)

export const elements = {
    searchForm: document.querySelector('.search'),
    searchInput: document.querySelector('.search__field'),
    searchResList: document.querySelector('.results__list')
};

0 个答案:

没有答案