简体   繁体   English

Phonegap 7搞砸了package.json

[英]Phonegap 7 is messing with package.json

I'm trying to upgrade my phonegap/cordova android application which is build with react and webpack to its latest version 7.0.1 我正在尝试将用react和webpack构建的phonegap / cordova android应用程序升级到最新版本7.0.1

When I execute phonegap build android one of the new things phonegap is doing is to automatically update the package.json with all the dependencies of my cordova plugins into the file and additionally to add a section with regards cordova, check the below snippet: 当我执行phonegap build android时,phonegap所做的新动作之一是自动将具有我Cordova插件的所有依赖关系的package.json更新到文件中,此外还要添加关于cordova的部分,请检查以下代码段:

After running phonegap build , I see within package.json: 运行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": {}
    }
}

This is somewhat explained in the new version of phonegap 7+ here 这在PhoneGap的新版本有所解释7+ 这里

My problem is that when this happens I can no longer build my application or start it as standalone with npm start since some of the dependencies are creating the following error: 我的问题是,发生这种情况时,我将无法再构建应用程序或使用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
| 

How it is possible to overcome this issue? 如何克服这个问题? Can I add some configuration to prevent this from happening? 我可以添加一些配置来防止这种情况发生吗?

I have found a workaround to overcome this since it seems that we have to manually exclude the packages of cordova when building your react application, you can do the following (I dont know if there is any better solution to this): 我发现了一个解决方法,可以解决此问题,因为似乎在构建您的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-.*/)
    },

 ...

When you declare your entries make sure to exclude the cordova dependencies 声明条目时,请确保排除cordova依赖项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 package.json 安装依赖项? - How to install dependencies from package.json? 自定义cordova插件中无效的package.json - Invalid package.json in Custom cordova plugin 离子平台添加android引发package.json的语法错误 - Ionic platform add android throws Syntax error for package.json 更新package.json以添加android以反应原生 - updating package.json to add android to react native 安装没有package.json文件的Cordova插件 - Install Cordova plugin without package.json file on it 如何在 package.json 脚本中运行多个命令? - How can I run multiple commands in package.json scripts? CordovaError:插件无效! ..\\hello 需要一个有效的 package.json - CordovaError: Invalid Plugin! ..\hello needs a valid package.json React Native:package.json中的平台特定代码 - React Native: Platform specific code in package.json 通过Android USB连接的Firefox移动插件SDK错误-package.json没有“ main”条目 - Firefox Mobile Addon SDK via Android usb connection error - package.json does not have a 'main' entry 错误:“package.json”中的 react-native 版本与“node_modules”中安装的版本不匹配 - Error: react-native version in "package.json" doesn't match the installed version in "node_modules"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM