bundle.js: 2 Uncaught ReferenceError: require не определен в bundle.js: 2 - PullRequest
0 голосов
/ 27 мая 2018

Я получаю эту ошибку, когда пытаюсь создать веб-страницу с помощью реакции и веб-пакета.Это мой файл bundle.js.

var appRoot = "/";
var Builder = require('systemjs-builder');

// optional constructor options
// sets the baseURL and loads the configuration file
var builder = new Builder("/", 'config.js');

function build(entry, output) {
    var message = entry + " --> " + output;
    var begin = new Date();
    console.log("---- Build started @ " + begin.toLocaleTimeString() + " # " + message);
    builder
    .bundle(entry, output, {
        minify: true,
        mangle: true
    })
    .then(function (output) {
        var index = 1;
        output.modules.forEach(function (m) {
            ////output.modules.sort().forEach(function (m) {
            console.log(" #" + index++ + " " + m);
        });

        logEnd(begin, message);
    })
    .catch(function (err) {
        console.log('!!! error');
        console.log(err);
        logEnd(begin, message);
        throw err;
    });
}

function logEnd(begin, message) {
    var end = new Date();
    console.log("---- Build completed @ " + end.toLocaleTimeString() +" 
    (" 

    + (end - begin) + " ms) # " + message);
    }


build(appRoot + 'app.js', __dirname + '/build/app-bundle.js')
build(appRoot + 'contact/module.js', __dirname + '/build/app-bundle-contact.js')
build(appRoot + 'about/module.js', __dirname + '/build/app-bundle-about.js')

когда я искал ошибку, я нашел решение под названием «использование внешних устройств», которое не работало.как я могу решить эту проблему?в чем его причина?

1 Ответ

0 голосов
/ 31 мая 2018

Я нашел причину этой проблемы.это потому, что я скопировал файл webpack.config.js из Интернета, а не сгенерировал его из модуля webpack-create-config.который, в свою очередь, не создал файл bundle.js с необходимыми зависимостями.

Я следовал этому руководству по установке и настройке веб-пакета и запуска моего приложения реакции.

...