Как потребовать npm пакет «все города» в веб-пакете? - PullRequest
0 голосов
/ 09 марта 2020

Я хочу получить массив всех городов мира, но при установке пакета NPM во всех городах сначала возникла ошибка fs, после того как я вставил fs: 'empty' в веб-пакет, произошла ошибка:

Я не знаю, как удалить пробелы в stackoverflow. Я извиняюсь

Uncaught TypeError: Object (...) не является функцией в модуле. (index.bundle. js: 25) в модуле. (index.bundle. js: 25) в n (index.bundle. js: 1) в модуле. (index.bundle. js: 25) в n (index.bundle. js: 1) в index.bundle. js: 1 в index.bundle. js: 1

index. js


const cities = require('all-the-cities').default;

console.log(cities);


webpack.config

const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const pug = {
  test: /\.pug$/,
  use: ['html-loader?attrs=false', 'pug-html-loader']
};

module.exports = {
  node: {
    fs: 'empty'
  },
  entry: {
    index: './src/index.js'
  },
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [{
      test: /\.scss$/,
      use: ExtractTextPlugin.extract({
        fallback: 'style-loader',
        use: ['css-loader?url=false', 'sass-loader']
      })
    }, pug, {
      test: /\.svg$/,
      loader: 'svg-inline-loader'
    }, {
      test: /\.(gif|png|jpe?g|svg)$/i,
      use: [
        'file-loader',
        {
          loader: 'image-webpack-loader',
          options: {
            bypassOnDebug: true, // webpack@1.x
            disable: true, // webpack@2.x and newer
          },
        },
      ],
    }, {
      test: /\.(png|jpg|gif)$/i,
      use: [{
        loader: 'url-loader',
        options: {
          limit: 8192,
        },
      }, ],
    }, ],
  },
  plugins: [
    new ExtractTextPlugin("[name].css"),
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: './src/index.pug',
      inject: false
    }),
    new webpack.ProvidePlugin({
      $: 'jquery',
      jQuery: 'jquery',
      'window.jQuery': 'jquery'
    })
  ]
};

...