使用 babel 7.5.5、core-js 3.1.4 和 webpack 4.38.0,我如何从转译中排除 core-js?
我不想node_modules完全排除,因为我有需要转译的库
如果我使用exclude: /node_modules\/(core-js)/,一个 core-js 模块会抛出
类型错误:$ 不是函数
这让我有另外两个选择。
useBuiltIns: entry而不是使用,因为在这种情况下exclude: /node_modules/\(core-js)/有效,并且importcore.js 位于 main.js 的顶部这两个选项对我来说似乎都不是很好的解决方案,因为usage自 7.4以来“不再是实验性的”。
有什么办法可以使用用法让它工作吗?它是 babel-loader 还是 babel 中的错误?还是我的配置有问题?
这是我的 Webpack 配置:
const path = require('path');
const webpack = require('webpack');
module.exports = {
mode: 'production',
entry: {
main: ['./src/main'],
},
output: {
path: path.resolve(__dirname, './build/'),
publicPath: '/build/'
},
module: {
rules: [
{
test: /\.js$/, …Run Code Online (Sandbox Code Playgroud) 我专门收到此错误上RUN npm install的Dockerfile:
> core-js@2.6.11 postinstall /app/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
The command '/bin/sh -c npm install' returned a non-zero code: 1
Run Code Online (Sandbox Code Playgroud)
当我通过 查看包依赖关系树时npm ll,我看到 core-js 被 loopbackjs 使用。我正在使用版本loopback 3.0.0。
我已经在这里和这里尝试了解决方法,将其放在之前npm install:
RUN npm config set unsafe-perm true
Run Code Online (Sandbox Code Playgroud)
但同样的结果。
这是完整的相关错误日志:
Step 6/9 : RUN npm install
---> Running in 10ca507be4fa
npm WARN deprecated nsp@2.8.1: The Node Security Platform service is shutting down 9/30 - https://blog.npmjs.org/post/175511531085/the-node-security-platform-service-is-shutting
npm …Run Code Online (Sandbox Code Playgroud) 这是我的vue.config.js文件:
module.exports = {
configureWebpack: {
externals: {
"vue": "Vue",
"core-js": "core-js",
},
},
};
Run Code Online (Sandbox Code Playgroud)
通过此配置,vue.js (Vue) 库被排除,我可以从 CDN 链接它。
但core-js无论如何都已打包并且不被识别为外部库。
我的配置有什么问题吗?
我将 CollectionPage 的组件更改为箭头函数组件,而不仅仅是普通函数,然后出现此错误,但我不知道为什么当我对许多其他组件执行相同操作时它没有抛出此错误。这是组件代码
import { from } from 'core-js/fn/array'
import React from 'react'
import { useParams } from 'react-router-dom'
import Products from '../Products/Products'
import {H1} from '../../Style/global'
const CollectionPage=()=> {
const {collectionTitle}= useParams()
return (
<div style={{marginTop:96}}>
<H1>{collectionTitle} Collection</H1>
<Products collectionTitle={collectionTitle}/>
</div>
)
}
export default CollectionPage
Run Code Online (Sandbox Code Playgroud)
顺便说一句,这是一个 react webpack 项目,这是我的 webpack 配置:
const path = require('path')
const HTMLPlugin = require('html-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin');
module.exports ={
entry :"./src/index.js",
output:{
path:path.resolve(__dirname,"./dist"),
filename:'index.js',
},
plugins:[
new HTMLPlugin({template:'./src/index.html'}),
new CopyPlugin({
patterns: [ …Run Code Online (Sandbox Code Playgroud) core-js ×5
javascript ×3
webpack ×3
node.js ×2
reactjs ×2
babel-loader ×1
babeljs ×1
docker ×1
loopbackjs ×1
npm ×1
post-install ×1
vue-cli ×1
vue.js ×1