【问题标题】:node.js : webpack : Babel : Unknown substitution "BODY" givennode.js:webpack:Babel:未知替换“BODY”给定
【发布时间】:2019-07-22 15:04:57
【问题描述】:

我是 node.js 的新手。以下是我运行“npm run build-web”(运行“webpack --progress”并复制结果)时得到的结果。任何帮助将不胜感激。

儿童中心引脚: 哈希:92640a144e27eefff6af 时间:1663ms 建于:2019 年 2 月 28 日下午 5:07:50 1 项资产 入口点 centerPin = centerPin.bundle.js [0] ./src/screens/resources/web/lib/centerPin.js 5.83 KiB {0} [内置] [失败] [1 错误]

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or

'production' 为每个环境启用默认值。 您还可以将其设置为“无”以禁用任何默认行为。了解更多:https://webpack.js.org/concepts/mode/

ERROR in ./src/screens/resources/web/lib/centerPin.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Unknown substitution "BODY" given
    at Object.keys.forEach.key (/home/accent/code/treecheckerapp/app/treeChecker/node_modules/@babel/template/lib/populate.js:35:15)
    at Array.forEach (<anonymous>)
    at populatePlaceholders (/home/accent/code/treecheckerapp/app/treeChecker/node_modules/@babel/template/lib/populate.js:33:31)

这是我的 package.json :

{   "name": "treeChecker",   "version": "0.0.1",   "private": true,   "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest",
    "build": "webpack",
    "build-web": "webpack --progress && cp -r \"./src/screens/resources/web\" \"./android/app/src/main/assets\"",
    "android-linux": "react-native bundle --platform android --dev false --entry-file index.android.js --bundle-out put android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res && react-native run-and roid",
    "bundle": "react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output and roid/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res",
    "android-linux-rel": "react-native bundle --platform android --dev false --entry-file index.android.js --bundle
-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res && react-native run
-android --variant=release"   },   "dependencies": {
    "axios": "^0.18.0",
    "lodash": "^4.17.4",
    "npm-check-updates": "^2.15.0",
    "react": "16.8.3",
    "react-native": "0.58.5",
    "react-native-autocomplete-input": "^3.4.0",
    "react-native-button-component": "^0.2.28",
    "react-native-elements": "^1.1.0",
    "react-native-fs": "^2.8.1",
    "react-native-image-picker": "^0.28.0",
    "react-native-localization": "^2.1.0",
    "react-native-offline": "^4.3.0",
    "react-native-progress": "^3.4.0",
    "react-native-router-flux": "^4.0.0-beta.21",
    "react-native-simple-compass": "^1.0.0",
    "react-native-simple-dialogs": "^1.1.0",
    "react-native-spinkit": "^1.1.1",
    "react-native-static-server": "^0.4.1",
    "react-native-toast-native": "^1.2.1",
    "react-native-vector-icons": "^6.3.0",
    "react-native-viewpager": "^0.2.13",
    "react-native-webview-messaging": "^1.1.0",
    "react-navigation": "^3.3.2",
    "react-redux": "^6.0.1",
    "redux": "^4.0.1",
    "redux-persist": "^5.10.0",
    "redux-thunk": "^2.2.0"   },   "devDependencies": {
    "async": "^2.6.2",
    "babel-core": "^6.26.3",
    "babel-jest": "24.1.0",
    "babel-loader": "^8.0.5",
    "babel-preset-env": "^1.6.0",
    "babel-preset-react-native": "4.0.1",
    "eslint-config-rallycoding": "^3.2.0",
    "html-webpack-inline-source-plugin": "0.0.10",
    "html-webpack-plugin": "^3.2.0",
    "jest": "24.1.0",
    "path": "^0.12.7",
    "react-test-renderer": "16.8.3",
    "webpack": "^4.29.6",
    "webpack-cli": "^3.2.3"   },   "jest": {
    "preset": "react-native"   } }

这是我的 webpack.config.js

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');

module.exports = [
  {
    name: "createAOI",
    entry: {
      createAOI: './src/screens/resources/web/lib/createAOI.js',
    },
    output: {
      path: path.join(__dirname, 'src/screens/resources/web/'),
      filename: 'createAOI.bundle.js',
    },
    module: {
      rules: [{
        test: /\.js$/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: [
              ['env', {
                targets: {
                  browsers: ['last 2 versions', 'safari >= 9.3']
                }
              }]
            ]
          }
        }
      }]
    },
    plugins: [
      new HtmlWebpackPlugin({
        template: './src/screens/resources/web/createAOI.tpl.html',
        inlineSource: 'createAOI.bundle.js',
        filename: 'createAOI.html',
        cache: false,
      }),
      new HtmlWebpackInlineSourcePlugin(),
    ]
  },
  {
    name: "baseMap",
    entry: {
      baseMap: './src/screens/resources/web/lib/baseMap.js',
    },
    output: {
      path: path.join(__dirname, 'src/screens/resources/web/'),
      filename: 'baseMap.bundle.js',
    },
    module: {
      rules: [{
        test: /\.js$/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: [
              ['env', {
                targets: {
                  browsers: ['last 2 versions', 'safari >= 9.3']
                }
              }]
            ]
          }
        }
      }]
    },
    plugins: [
      new HtmlWebpackPlugin({
        template: './src/screens/resources/web/baseMap.tpl.html',
        inlineSource: 'baseMap.bundle.js',
        filename: 'baseMap.html',
        cache: false,
      }),
      new HtmlWebpackInlineSourcePlugin(),
    ]
  },
  {
    name: "centerPin",
    entry: {
      centerPin: './src/screens/resources/web/lib/centerPin.js',
    },
    output: {
      path: path.join(__dirname, 'src/screens/resources/web/'),
      filename: 'centerPin.bundle.js',
    },
    module: {
      rules: [{
        test: /\.js$/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: [
              ['env', {
                targets: {
                  browsers: ['last 2 versions', 'safari >= 9.3']
                }
              }]
            ]
          }
        }
      }]
    },
    plugins: [
      new HtmlWebpackPlugin({
        template: './src/screens/resources/web/centerPin.tpl.html',
        inlineSource: 'centerPin.bundle.js',
        filename: 'centerPin.html',
        cache: false,
      }),
      new HtmlWebpackInlineSourcePlugin(),
    ]
  },
]

【问题讨论】:

    标签: javascript node.js webpack


    【解决方案1】:

    通常当某些 babel 插件或预设的版本与 babel core 不同时,您会收到此错误。尝试将其更新到相同的版本。

    https://github.com/babel/babel/issues/7801

    【讨论】:

      猜你喜欢
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-03
      • 2017-09-29
      • 1970-01-01
      • 2011-11-04
      • 2021-03-23
      相关资源
      最近更新 更多