当我运行命令'npm run build'时,出现此错误:
./src/app.js中的ERROR模块构建失败(来自 ./node_modules/babel-loader/lib/index.js):错误:找不到模块 来自'F:\ Project \ frontend-project-lvl1'的'@ babel / preset-present-env' 在Function.resolveSync [作为同步](F:\ Project \ frontend-project-lvl1 \ node_modules \ resolve \ lib \ sync.js:89:15) 在resolveStandardizedName(F:\ Project \ frontend-project-lvl1 \ node_modules @ babel \ core \ lib \ config \ files \ plugins.js:101:31) 在resolvePreset(F:\ Project \ frontend-project-lvl1 \ node_modules @ babel \ core \ lib \ config \ files \ plugins.js:58:10) 在loadPreset(F:\ Project \ frontend-project-lvl1 \ node_modules @ babel \ core \ lib \ config \ files \ plugins.js:77:20) 在createDescriptor上(F:\ Project \ frontend-project-lvl1 \ node_modules @ babel \ core \ lib \ config \ config-descriptors.js:154:9) 在F:\ Project \ frontend-project-lvl1 \ node_modules @ babel \ core \ lib \ config \ config-descriptors.js:109:50 在Array.map() 在createDescriptors上(F:\ Project \ frontend-project-lvl1 \ node_modules @ babel \ core \ lib \ config \ config-descriptors.js:109:29) 在createPresetDescriptors(F:\ Project \ frontend-project-lvl1 \ node_modules @ babel \ core \ lib \ config \ config-descriptors.js:101:10) 在预设位置(F:\ Project \ frontend-project-lvl1 \ node_modules @ babel \ core \ lib \ config \ config-descriptors.js:47:19) 在mergeChainOpts(F:\ Project \ frontend-project-lvl1 \ node_modules @ babel \ core \ lib \ config \ config-chain.js:320:26) 在F:\ Project \ frontend-project-lvl1 \ node_modules @ babel \ core \ lib \ config \ config-chain.js:283:7 在Generator.next() 在buildRootChain(F:\ Project \ frontend-project-lvl1 \ node_modules @ babel \ core \ lib \ config \ config-chain.js:90:27) 在buildRootChain.next() 在loadPrivatePartialConfig(F:\ Project \ frontend-project-lvl1 \ node_modules @ babel \ core \ lib \ config \ partial.js:95:62) 在loadPrivatePartialConfig.next() 在功能。 (F:\ Project \ frontend-project-lvl1 \ node_modules @ babel \ core \ lib \ config \ partial.js:120:25) 在Generator.next() 在EvaluationSync(F:\ Project \ frontend-project-lvl1 \ node_modules \ gensync \ index.js:244:28) 在Function.sync(F:\ Project \ frontend-project-lvl1 \ node_modules \ gensync \ index.js:84:14) 在对象。 (F:\ Project \ frontend-project-lvl1 \ node_modules @ babel \ core \ lib \ config \ index.js:41:61) 在对象。 (F:\ Project \ frontend-project-lvl1 \ node_modules \ babel-loader \ lib \ index.js:151:26) 在Generator.next() 在asyncGeneratorStep(F:\ Project \ frontend-project-lvl1 \ node_modules \ babel-loader \ lib \ index.js:3:103) 在_next(F:\ Project \ frontend-project-lvl1 \ node_modules \ babel-loader \ lib \ index.js:5:194) 在F:\ Project \ frontend-project-lvl1 \ node_modules \ babel-loader \ lib \ index.js:5:364 在新的Promise() 在对象。 (F:\ Project \ frontend-project-lvl1 \ node_modules \ babel-loader \ lib \ index.js:5:97) 在Object._loader(F:\ Project \ frontend-project-lvl1 \ node_modules \ babel-loader \ lib \ index.js:231:18) 在Object.loader(F:\ Project \ frontend-project-lvl1 \ node_modules \ babel-loader \ lib \ index.js:64:18) 在对象。 (F:\ Project \ frontend-project-lvl1 \ node_modules \ babel-loader \ lib \ index.js:59:12)
我的配置是: package.json
{
"name": "frontend-project-lvl1",
"version": "1.0.0",
"description": "",
"main": "Main.js",
"scripts": {
"build": "webpack",
"start": "webpack --watch"
},
"repository": {
"type": "git",
"url": "git+https://github.com/an-palna/frontend-project-lvl1.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/an-palna/frontend-project-lvl1/issues"
},
"homepage": "https://github.com/an-palna/frontend-project-lvl1#readme",
"devDependencies": {
"@babel/core": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"babel-loader": "^8.1.0",
"css-loader": "^3.5.3",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"node-sass": "^4.14.1",
"sass-loader": "^8.0.2",
"style-loader": "^1.2.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
},
"files": [
"dist"
]
}
webpack.config.js
const path = require('path');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
entry: './src/app.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
},
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', { modules: false }]
]
}
}
}
]
},
plugins: [
new ExtractTextPlugin('style.css')
]
};
babel.config
module.exports = {
presets: [
['@babel/present-env', {
targets: {
node: 'current',
firefox: '60',
chrome: '67',
safari: '11.1',
},
}],
],
};
.babelrc
{
"presets": [
"@babel/preset-env"
]
}
答案 0 :(得分:1)
在您的 babel.config
中将['@babel/present-env'
(从['@babel/preset-env'
更改为public interface IWeaponPrimaryAction
{
void PerformPrimaryAction();
}
public interface IWeaponAction
{
void PrimaryAction();
}
public class Shoot :IWeaponAction
{
public void PrimaryAction()
{
//Fire in the hole
}
}
public class Swing :IWeaponAction
{
public void PrimaryAction()
{
//Into pieces
}
}
public class ShotGun : IWeaponPrimaryAction
{
private IWeaponAction _action = new Shoot();
public void PerformPrimaryAction()
{
_action.PrimaryAction();
}
}
public class Kanata : IWeaponPrimaryAction
{
private IWeaponAction _action = new Swing();
public void PerformPrimaryAction()
{
_action.PrimaryAction();
}
}