@lilwings

Как доабвить import в webpack конфиге?

Вот код конфигурации webpack:

webpack.config.js:
import * as Webpack from "webpack";

const path = require('path');

module.exports = {
    mode: 'development',
    devtool: 'source-map',

    entry: { main: './src/js/index.js' },
    output: {
        path: path.resolve(__dirname, './js'),
        filename: 'main.js',
        library: "abra"
    },
    module: {
        rules: [
            {
                test: /\.html$/,
                exclude: /node_modules/,
                use: {
                    loader: 'html-loader',
                    options: {
                        attrs: [':data-src'],
                        interpolate: true
                    }
                }
            }
        ]
    },
    plugins: [
        new Webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery',
            'window.$': 'jquery'
        }),
    ],
    resolve: {
        extensions: ['.js', '.html']
    }
};


error:
(function (exports, require, module, __filename, __dirname) { import * as Webpack from "webpack";
                                                              ^^^^^^

SyntaxError: Cannot use import statement outside a module
←[90m    at new Script (vm.js:88:7)←[39m
    at NativeCompileCache._moduleCompile (C:\projects\html - scss - ts\abra\node_modules\←[4mv8-compile-cache←[24m\v8-compile-cache.js:240:18)
    at Module._compile (C:\projects\html - scss - ts\abra\node_modules\←[4mv8-compile-cache←[24m\v8-compile-cache.js:186:36)
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:1002:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:901:14)←[39m
←[90m    at Module.require (internal/modules/cjs/loader.js:1044:19)←[39m
    at require (C:\projects\html - scss - ts\abra\node_modules\←[4mv8-compile-cache←[24m\v8-compile-cache.js:161:20)
    at WEBPACK_OPTIONS (C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack-cli←[24m\bin\utils\convert-argv.js:114:13)
    at requireConfig (C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack-cli←[24m\bin\utils\convert-argv.js:116:6)
    at C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack-cli←[24m\bin\utils\convert-argv.js:123:17
    at Array.forEach (<anonymous>)
    at module.exports (C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack-cli←[24m\bin\utils\convert-argv.js:121:15)
    at C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack-cli←[24m\bin\cli.js:71:45
    at Object.parse (C:\projects\html - scss - ts\abra\node_modules\←[4myargs←[24m\yargs.js:567:18)
    at C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack-cli←[24m\bin\cli.js:49:8
    at Object.<anonymous> (C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack-cli←[24m\bin\cli.js:366:3)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1158:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:1002:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:901:14)←[39m
←[90m    at Module.require (internal/modules/cjs/loader.js:1044:19)←[39m
←[90m    at require (internal/modules/cjs/helpers.js:77:18)←[39m
    at Object.<anonymous> (C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack←[24m\bin\webpack.js:156:2)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1158:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:1002:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:901:14)←[39m
←[90m    at Function.executeUserEntryPoint [as<code> runMain] (internal/modules/run_main.js:74:12)←[39m
←[90m    at internal/main/run_main_module.j</code>s:18:47←[39m
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Process finished with exit code 1


Если убрать import * as Webpack from "webpack"; то ошибка такая:

ReferenceError: Webpack is not defined
    at Object.<anonymous> (C:\projects\html - scss - ts\abra\webpack.config.js:29:13)
    at Module._compile (C:\projects\html - scss - ts\abra\node_modules\←[4mv8-compile-cache←[24m\v8-compile-cache.js:192:30)
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:1002:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:901:14)←[39m
←[90m    at Module.require (internal/modules/cjs/loader.js:1044:19)←[39m
    at require (C:\projects\html - scss - ts\abra\node_modules\←[4mv8-compile-cache←[24m\v8-compile-cache.js:161:20)
    at WEBPACK_OPTIONS (C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack-cli←[24m\bin\utils\convert-argv.js:114:13)
    at requireConfig (C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack-cli←[24m\bin\utils\convert-argv.js:116:6)
    at C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack-cli←[24m\bin\utils\convert-argv.js:123:17
    at Array.forEach (<anonymous>)
    at module.exports (C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack-cli←[24m\bin\utils\convert-argv.js:121:15)
    at C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack-cli←[24m\bin\cli.js:71:45
    at Object.parse (C:\projects\html - scss - ts\abra\node_modules\←[4myargs←[24m\yargs.js:567:18)
    at C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack-cli←[24m\bin\cli.js:49:8
    at Object.<anonymous> (C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack-cli←[24m\bin\cli.js:366:3)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1158:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:1002:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:901:14)←[39m
←[90m    at Module.require (internal/modules/cjs/loader.js:1044:19)←[39m
←[90m    at require (internal/modules/cjs/helpers.js:77:18)←[39m
    at Object.<anonymous> (C:\projects\html - scss - ts\abra\node_modules\←[4mwebpack←[24m\bin\webpack.js:156:2)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1158:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:1002:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:901:14)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)←[39m
←[90m    at internal/main/run_main_module.js:18:47←[39m
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
  • Вопрос задан
  • 25 просмотров
Решения вопроса 1
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
29 мая 2020, в 01:41
850 руб./за проект
29 мая 2020, в 00:02
5000 руб./за проект
28 мая 2020, в 23:42
10000 руб./за проект