Webpack and Express - Critical Dependencies Warning

后端 未结 3 799
执笔经年
执笔经年 2020-12-14 02:10

I have the following webpack.config.ts:

var webpack = require( \'webpack\' );
var path = require( \'path\' );

module.exports = {

  entry: [
           


        
相关标签:
3条回答
  • 2020-12-14 02:44

    Instead of excluding all of the npm dependencies to be bundled with nodeExternals you can also exclude only express by natively requiring it by replacing

    import express from 'express';
    // Or
    const express = require('express');
    

    To

    const express = __non_webpack_require__('express');
    

    That will suppress the warning caused by express

    0 讨论(0)
  • 2020-12-14 02:49

    For those that only need to remove the express due to the view lib as mentioned here you can also explicitly target express in externals from your webpack config.

    externals: [{ 'express': { commonjs: 'express' } }]

    0 讨论(0)
  • 2020-12-14 03:07

    Use webpack-node-externals.

    const nodeExternals = require('webpack-node-externals');
    
    {
      target: 'node',
      externals: [nodeExternals()],
    }
    

    https://www.npmjs.com/package/webpack-node-externals

    0 讨论(0)
提交回复
热议问题