首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Uncaught:$不是核心js中的一个函数。

Uncaught:$不是核心js中的一个函数。
EN

Stack Overflow用户
提问于 2020-12-14 17:26:07
回答 1查看 3.3K关注 0票数 1

我正在尝试安装BigCommerce开放检查脚本,当我试图在本地运行基本安装时,我目前正在收到这个错误:

代码语言:javascript
复制
Uncaught TypeError: $ is not a function
at eval (es.array.index-of.js?c975:15)
at Object../node_modules/core-js/modules/es.array.index-of.js

该文件是:

代码语言:javascript
复制
'use strict';
var $ = require('../internals/export');
var $indexOf = require('../internals/array-includes').indexOf;
var arrayMethodIsStrict = require('../internals/array-method-is-strict');
var arrayMethodUsesToLength = require('../internals/array-method-uses-to-length');

var nativeIndexOf = [].indexOf;

var NEGATIVE_ZERO = !!nativeIndexOf && 1 / [1].indexOf(1, -0) < 0;
var STRICT_METHOD = arrayMethodIsStrict('indexOf');
var USES_TO_LENGTH = arrayMethodUsesToLength('indexOf', { ACCESSORS: true, 1: 0 });

// `Array.prototype.indexOf` method
// https://tc39.github.io/ecma262/#sec-array.prototype.indexof
$({ target: 'Array', proto: true, forced: NEGATIVE_ZERO || !STRICT_METHOD || !USES_TO_LENGTH }, {
  indexOf: function indexOf(searchElement /* , fromIndex = 0 */) {
    return NEGATIVE_ZERO
      // convert -0 to +0
      ? nativeIndexOf.apply(this, arguments) || 0
      : $indexOf(this, searchElement, arguments.length > 1 ? arguments[1] : undefined);
  }
});

到目前为止,我已经多次尝试更新核心js和NPM,但没有取得任何进展。

EN

回答 1

Stack Overflow用户

发布于 2021-08-18 16:37:13

核心-js不应该由Babel编译。当使用webpack + babel编译您的代码时,您需要确保babel-加载程序的webpack模块规则不包括核心-js。

备选案文1

告诉webpack不要对node_modules中的任何依赖项使用babel-加载程序。由于core-js是node_modules中的一个依赖项,所以这不包括由babel处理的核心js。

代码语言:javascript
复制
// webpack.config.js
// This code snippet shows only the relevant part of the webpack config
module.exports = {
  module: {
    rules: [
      {
        test: /\.m?(j|t)sx?$/,
        // Excluding node_modules means that core-js will not be compiled
        exclude: /node_modules/,
        use: ['babel-loader']
      }
    ]
  }
}

选项2

告诉webpack用babel编译所有依赖项,但核心-js依赖项除外:

代码语言:javascript
复制
// webpack.config.js
// This code snippet shows only the relevant part of the webpack config
module.exports = {
  module: {
    rules: [
      {
        test: /\.m?(j|t)sx?$/,
        // Compile all node_modules except core-js
        include: {
          and: [/node_modules/],
          not: [/core-js/]
        },
        use: ['babel-loader']
      }
    ]
  }
}

相关链接

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65293577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档