【问题标题】:Phonegap 7 is messing with package.jsonPhonegap 7 搞砸了 package.json
【发布时间】:2017-09-14 15:34:50
【问题描述】:

我正在尝试将使用 react 和 webpack 构建的 phonegap/cordova android 应用程序升级到其最新版本 7.0.1

当我执行 phonegap build android 时,phonegap 正在做的新事情之一是自动将 package.json 与我的 cordova 插件的所有依赖项更新到文件中,另外添加一个关于 cordova 的部分,检查下面的 sn -p:

运行phonegap build后,我在package.json中看到:

"dependencies": {            
        // my normal dependencies
        ...
        "counterpart": "0.18.2",
        "react": "15.6.1",
        ...

        // added by phonegap    
        "cordova-android": "^6.2.3",
        "cordova-plugin-battery-status": "~1.1.1",
        "cordova-plugin-camera": "~2.1.1",
        "cordova-plugin-console": "~1.0.2",
        "cordova-plugin-contacts": "~2.0.1",
        "cordova-plugin-crosswalk-webview": "^2.3.0",
        "cordova-plugin-customurlscheme": "~4.3.0",
        "cordova-plugin-device": "~1.1.2",
        "cordova-plugin-device-motion": "~1.2.0",
        "cordova-plugin-device-orientation": "^1.0.7",
        "cordova-plugin-dialogs": "~1.2.0",
        "cordova-plugin-file": "~4.1.1",
        "cordova-plugin-file-transfer": "~1.5.0",
        "cordova-plugin-geolocation": "~2.2.0",
        "cordova-plugin-globalization": "~1.0.3",
        "cordova-plugin-inappbrowser": "~1.3.0",
        "cordova-plugin-media": "~2.2.0",
        "cordova-plugin-media-capture": "~1.2.0",
        "cordova-plugin-network-information": "~1.2.1",
        "cordova-plugin-screen-orientation": "^2.0.1",
        "cordova-plugin-screensize": "1.3.1",
        "cordova-plugin-splashscreen": "~3.2.1",
        "cordova-plugin-statusbar": "~2.1.3",
        "cordova-plugin-vibration": "~2.1.5",
        "cordova-plugin-whitelist": "~1.2.2"
    },
    "cordova": {
    "platforms": [
        "android"
    ],
    "plugins": {
        "cordova-plugin-battery-status": {},
        "cordova-plugin-camera": {},
        "cordova-plugin-console": {},
        "cordova-plugin-contacts": {},
        "cordova-plugin-crosswalk-webview": {},
        "cordova-plugin-customurlscheme": {
            "URL_SCHEME": "essforms",
            "ANDROID_SCHEME": " ",
            "ANDROID_HOST": " ",
            "ANDROID_PATHPREFIX": "/"
        },
        "cordova-plugin-device": {},
        "cordova-plugin-device-motion": {},
        "cordova-plugin-device-orientation": {},
        "cordova-plugin-dialogs": {},
        "cordova-plugin-file": {},
        "cordova-plugin-file-transfer": {},
        "cordova-plugin-geolocation": {},
        "cordova-plugin-globalization": {},
        "cordova-plugin-inappbrowser": {},
        "cordova-plugin-media": {},
        "cordova-plugin-media-capture": {},
        "cordova-plugin-network-information": {},
        "cordova-plugin-screen-orientation": {},
        "cordova-plugin-screensize": {},
        "cordova-plugin-splashscreen": {},
        "cordova-plugin-statusbar": {},
        "cordova-plugin-vibration": {},
        "cordova-plugin-whitelist": {}
    }
}

这在新版phonegap 7+here中有所解释

我的问题是,发生这种情况时,我无法再构建我的应用程序或使用 npm start 独立启动它,因为某些依赖项会产生以下错误:

WARNING in ./node_modules/cordova-android/bin/templates/cordova/Api.js
118:30-79 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/cordova-android/bin/templates/cordova/Api.js
152:30-79 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/cordova-android/bin/lib/create.js
Module parse failed: /storage/projects/exus/inachus/source/ess-forms-android/node_modules/cordova-android/bin/lib/create.js Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
| #!/usr/bin/env node
| 

如何解决这个问题?我可以添加一些配置来防止这种情况发生吗?

【问题讨论】:

    标签: android reactjs cordova webpack phonegap-cli


    【解决方案1】:

    我找到了一种解决方法来克服这个问题,因为在构建你的 react 应用程序时似乎我们必须手动排除cordova的包,你可以执行以下操作(我不知道是否有更好的解决方案):

    ...
    
    function removeMatching(originalArray, regex) {
        var j = 0;
        while (j < originalArray.length) {
            if (regex.test(originalArray[j]))
                originalArray.splice(j, 1);
            else
                j++;
        }
        return originalArray;
    }
    
    module.exports = {
        entry: {
            vendor: removeMatching(Object.keys(require('./package.json').dependencies), /cordova-.*/)
        },
    
     ...
    

    当您声明您的条目时,请确保排除 cordova 依赖项

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-15
      • 2012-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多