D
D
Denis_13342021-04-03 09:35:12
Node.js
Denis_1334, 2021-04-03 09:35:12

How to import webpack config?

Why module.exportsdoes webpack work correctly when I use it.

const path = require('path')

const config = {
  entry:{
    main:'./src/index.js'
  },
  output: {
    filename: '[name].[contenthash].js',
    path: path.resolve(__dirname, 'dist')
  }
}

module.exports = config


But when used export/importin node.js

import path from 'path'

const config = {
  entry:{
    main:'./src/index.js'
  },
  output: {
    filename: '[name].[contenthash].js',
    path: path.resolve(__dirname, 'dist')
  }
}

export config


I'm getting an error

[webpack-cli] Failed to load 'C:\Users\denis\Desktop\ASP\webpack.config.js' config
[webpack-cli] TypeError: Invalid host defined options
    at eval (eval at dynamicImportLoader (C:\Users\denis\Desktop\ASP\node_modules\webpack-cli\lib\utils\dynamic-import-loader.js:5:21), <anonymous>:3:1)
    at loadConfig (C:\Users\denis\Desktop\ASP\node_modules\webpack-cli\lib\webpack-cli.js:1346:41)
    at WebpackCLI.resolveConfig (C:\Users\denis\Desktop\ASP\node_modules\webpack-cli\lib\webpack-cli.js:1454:44)
    at WebpackCLI.createCompiler (C:\Users\denis\Desktop\ASP\node_modules\webpack-cli\lib\webpack-cli.js:1839:33)
    at WebpackCLI.buildCommand (C:\Users\denis\Desktop\ASP\node_modules\webpack-cli\lib\webpack-cli.js:1954:31)
    at Command.<anonymous> (C:\Users\denis\Desktop\ASP\node_modules\webpack-cli\lib\webpack-cli.js:735:36)
    at Command.listener [as _actionHandler] (C:\Users\denis\Desktop\ASP\node_modules\webpack-cli\node_modules\commander\index.js:922:31)
    at Command._parseCommand (C:\Users\denis\Desktop\ASP\node_modules\webpack-cli\node_modules\commander\index.js:1503:14)
    at Command._dispatchSubcommand (C:\Users\denis\Desktop\ASP\node_modules\webpack-cli\node_modules\commander\index.js:1443:18)
    at Command._parseCommand (C:\Users\denis\Desktop\ASP\node_modules\webpack-cli\node_modules\commander\index.js:1460:12)


In package.jsonI put "type": "module" but still doesn't work

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question