Как исправить ошибку «Ошибка синтаксического анализа модуля: (... по умолчанию, ... опции) Неожиданный токен»? Webpack - PullRequest
0 голосов
/ 10 ноября 2019

Я создаю расширение для браузера и использую pageres для создания снимков экрана. Почему веб-пакет не работает?

Когда я связал этот "шаблон" , он работал, но так как я добавил require ('pageres'), он выдает ошибку:

ERROR in ./~/make-dir/index.js
Module parse failed: C:\Users\<user>\Desktop\webpack-modules2\node_modules\make-dir\index.js Unexpected token (42:2)
You may need an appropriate loader to handle this file type.
|       checkPath(input);
|       options = {
|               ...defaults,
|               ...options
|       };
 @ ./~/pageres/dist/index.js 16:16-35
 @ ./background_scripts/background.js

ERROR in ./~/pageres/~/capture-website/index.js
Module parse failed: C:\Users\<user>\Desktop\webpack-modules2\node_modules\pageres\node_modules\capture-website\index.js Unexpected token (145:2)
You may need an appropriate loader to handle this file type.
|               launchOptions: {},
|               _keepAlive: false,
|               ...options
|       };
|
 @ ./~/pageres/dist/index.js 17:23-49
 @ ./background_scripts/background.js

Я пытался удалить эти строки "... options, ... defaults", но ошибки удвоились.

Вот webpack.config.js

const path = require("path");

module.exports = {
    entry: {
        background_scripts: "./background_scripts/background.js",
        popup: "./popup/left-pad.js"
    },
    output: {
        path: path.resolve(__dirname, "addon"),
        filename: "[name]/index.js"
    },
    node: {
        fs: "empty"
    }
};

background.js

const Pageres = require('pageres');

var pageres = new Pageres({delay: 2})
        .src(window.location.href, ['1920x1080'])
        .src('data:text/html,<h1>Awesome!</h1>', ['1024x768'])
        .dest('screenshots')
        .run();

...