内容的栏目 * @param int $category 0列表 1频道 2单页 3外链 * @return array */ function category_list($forumlist, $model = 0, $display = 0, $category = 0) { if (empty($forumlist)) return NULL; static $cache = array(); $key = $model . '-' . $display . '-' . $category; if (isset($cache[$key])) return $cache[$key]; if ($display) { foreach ($forumlist as $k => $val) { if (1 == $val['display'] && 1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } else { foreach ($forumlist as $k => $val) { if (1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } return empty($cache[$key]) ? NULL : $cache[$key]; } /** * @param $forumlist 所有版块列表 不分模型 * @param int $display 0全部CMS栏目 1在首页和频道显示内容的栏目 * @param int $category 0列表 1频道 2单页 3外链 * @return array */ function category_list_show($forumlist, $display = 0, $category = 0) { if (empty($forumlist)) return NULL; static $cache = array(); $key = $display . '-' . $category; if (isset($cache[$key])) return $cache[$key]; if ($display) { foreach ($forumlist as $k => $val) { if (1 == $val['display'] && 1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } else { foreach ($forumlist as $k => $val) { if (1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } return empty($cache[$key]) ? NULL : $cache[$key]; } /** * @param $forumlist 所有版块列表 * @return mixed BBS栏目数据(仅列表) 尚未开放bbs频道功能 */ function forum_list($forumlist) { if (empty($forumlist)) return array(); static $cache = array(); if (isset($cache['bbs_forum_list'])) return $cache['bbs_forum_list']; $cache['bbs_forum_list'] = array(); foreach ($forumlist as $_fid => $_forum) { if ($_forum['type']) continue; $cache['bbs_forum_list'][$_fid] = $_forum; } return $cache['bbs_forum_list']; } // 导航显示的版块 function nav_list($forumlist) { if (empty($forumlist)) return NULL; static $cache = array(); if (isset($cache['nav_list'])) return $cache['nav_list']; foreach ($forumlist as $fid => $forum) { if (0 == $forum['nav_display']) { unset($forumlist[$fid]); } } return $cache['nav_list'] = $forumlist; } ?>javascript - Webpack 2.3.3 - TypeError: $export is not a function - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Webpack 2.3.3 - TypeError: $export is not a function - Stack Overflow

programmeradmin0浏览0评论

I have this Webpack config:

const path = require('path');

module.exports = {
  entry: ['babel-polyfill', './lib/index.js'],
  output: {
    path: path.resolve(__dirname + '/dist'),
    filename: 'suman.js'
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        options: {
          presets: ['latest'],
          plugins: ['transform-runtime']
        }
      }
    ]
  },

  node: {
    assert: 'empty',
    buffer: 'mock',
    child_process: 'empty',
    cluster: 'empty',
    console: 'mock',
    constants: 'empty',
    crypto: 'empty',
    dgram: 'empty',
    dns: 'mock',
    domain: 'empty',
    events: 'empty',
    fs: 'empty',
    http: 'empty',
    https: 'empty',
    module: 'empty',
    net: 'mock',
    os: 'empty',
    path: 'empty',
    process: 'mock',
    punycode: 'mock',
    querystring: 'empty',
    readline: 'empty',
    repl: 'empty',
    stream: 'empty',
    string_decoder: 'empty',
    timers: 'empty',
    tls: 'mock',
    tty: 'mock',
    url: 'empty',
    util: 'empty',
    v8: 'mock',
    vm: 'empty',
    zlib: 'empty',
  }
};

I run $webpack at the mand line and I get an outputted file, I load the file in the browser like so:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Suman tests</title>
  <script src="../../../dist/suman.js"></script>
</head>
<body>

</body>
</html>

If I load this html file in the browser, I get:

suman.js:48039 Uncaught TypeError: $export is not a function
    at Object.<anonymous> (suman.js:48039)
    at __webpack_require__ (suman.js:20)
    at Object.<anonymous> (suman.js:46862)
    at __webpack_require__ (suman.js:20)
    at Object.hasOwnProperty (suman.js:12300)
    at __webpack_require__ (suman.js:20)
    at Object.<anonymous> (suman.js:10477)
    at __webpack_require__ (suman.js:20)
    at Object.<anonymous> (suman.js:12321)
    at __webpack_require__ (suman.js:20)

I looked at a bunch of issues on Github and none of them seem to solve the problem. Anyone know what could be wrong?

I am on Webpack version 2.3.3.

on a side note - where can I find some polyfills for Node.js / NPM modules?

$export appears to be a function generated by Webpack, and here is some of it that appears in my output file:

var global = __webpack_require__(10),
    core = __webpack_require__(58),
    hide = __webpack_require__(33),
    redefine = __webpack_require__(34),
    ctx = __webpack_require__(59),
    PROTOTYPE = 'prototype';

var $export = function $export(type, name, source) {
  var IS_FORCED = type & $export.F,
      IS_GLOBAL = type & $export.G,
      IS_STATIC = type & $export.S,
      IS_PROTO = type & $export.P,
      IS_BIND = type & $export.B,
      target = IS_GLOBAL ? global : IS_STATIC ? global[name] || (global[name] = {}) : (global[name] || {})[PROTOTYPE],
      exports = IS_GLOBAL ? core : core[name] || (core[name] = {}),
      expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {}),
      key,
      own,
      out,
      exp;
  if (IS_GLOBAL) source = name;
  for (key in source) {

I have this Webpack config:

const path = require('path');

module.exports = {
  entry: ['babel-polyfill', './lib/index.js'],
  output: {
    path: path.resolve(__dirname + '/dist'),
    filename: 'suman.js'
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        options: {
          presets: ['latest'],
          plugins: ['transform-runtime']
        }
      }
    ]
  },

  node: {
    assert: 'empty',
    buffer: 'mock',
    child_process: 'empty',
    cluster: 'empty',
    console: 'mock',
    constants: 'empty',
    crypto: 'empty',
    dgram: 'empty',
    dns: 'mock',
    domain: 'empty',
    events: 'empty',
    fs: 'empty',
    http: 'empty',
    https: 'empty',
    module: 'empty',
    net: 'mock',
    os: 'empty',
    path: 'empty',
    process: 'mock',
    punycode: 'mock',
    querystring: 'empty',
    readline: 'empty',
    repl: 'empty',
    stream: 'empty',
    string_decoder: 'empty',
    timers: 'empty',
    tls: 'mock',
    tty: 'mock',
    url: 'empty',
    util: 'empty',
    v8: 'mock',
    vm: 'empty',
    zlib: 'empty',
  }
};

I run $webpack at the mand line and I get an outputted file, I load the file in the browser like so:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Suman tests</title>
  <script src="../../../dist/suman.js"></script>
</head>
<body>

</body>
</html>

If I load this html file in the browser, I get:

suman.js:48039 Uncaught TypeError: $export is not a function
    at Object.<anonymous> (suman.js:48039)
    at __webpack_require__ (suman.js:20)
    at Object.<anonymous> (suman.js:46862)
    at __webpack_require__ (suman.js:20)
    at Object.hasOwnProperty (suman.js:12300)
    at __webpack_require__ (suman.js:20)
    at Object.<anonymous> (suman.js:10477)
    at __webpack_require__ (suman.js:20)
    at Object.<anonymous> (suman.js:12321)
    at __webpack_require__ (suman.js:20)

I looked at a bunch of issues on Github and none of them seem to solve the problem. Anyone know what could be wrong?

I am on Webpack version 2.3.3.

on a side note - where can I find some polyfills for Node.js / NPM modules?

$export appears to be a function generated by Webpack, and here is some of it that appears in my output file:

var global = __webpack_require__(10),
    core = __webpack_require__(58),
    hide = __webpack_require__(33),
    redefine = __webpack_require__(34),
    ctx = __webpack_require__(59),
    PROTOTYPE = 'prototype';

var $export = function $export(type, name, source) {
  var IS_FORCED = type & $export.F,
      IS_GLOBAL = type & $export.G,
      IS_STATIC = type & $export.S,
      IS_PROTO = type & $export.P,
      IS_BIND = type & $export.B,
      target = IS_GLOBAL ? global : IS_STATIC ? global[name] || (global[name] = {}) : (global[name] || {})[PROTOTYPE],
      exports = IS_GLOBAL ? core : core[name] || (core[name] = {}),
      expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {}),
      key,
      own,
      out,
      exp;
  if (IS_GLOBAL) source = name;
  for (key in source) {
Share Improve this question edited Apr 5, 2017 at 5:30 Alexander Mills asked Apr 5, 2017 at 5:06 Alexander MillsAlexander Mills 100k166 gold badges536 silver badges913 bronze badges 4
  • What is $export? If that's what is failing, that is the place to start, and you haven't shown us the code for that. – loganfsmyth Commented Apr 5, 2017 at 5:20
  • You should also consider enabling sourcemaps with devtool: "source-map" so you get better stack traces. – loganfsmyth Commented Apr 5, 2017 at 5:22
  • @loganfsmyth $export function is not my code, it's the code generated by webpack, let me give you a link to it – Alexander Mills Commented Apr 5, 2017 at 5:28
  • @loganfsmyth I updated the question in response to your ment, thanks – Alexander Mills Commented Apr 5, 2017 at 5:30
Add a ment  | 

1 Answer 1

Reset to default 10

Along with

test: /\.js$/

you should have

exclude: /node_modules/

as you can see in the usage examples: https://github./babel/babel-loader#usage

e.g.

{
  test: /\.js$/,
  exclude: /node_modules/,
  loader: 'babel-loader',
  options: {
    presets: ['latest'],
    plugins: ['transform-runtime']
  }
}

In this case, you are using transform-runtime which means Babel will insert references to babel-runtime into your code. The issue is that without exclude: /node_modules/,, or at least exclude: /node_modules\/(?!babel-runtime)/,, you are also telling babel-runtime to insert references to itself inside itself, which creates circular dependencies that will break the code.

发布评论

评论列表(0)

  1. 暂无评论