NativeScript / nativescript-cli

Command-line interface for building NativeScript apps
https://www.npmjs.com/package/nativescript
Apache License 2.0
1.04k stars 196 forks source link

Can not install nativescript specific version 6.x.x #5747

Open minhson95th opened 1 year ago

minhson95th commented 1 year ago

Issue Description

I try to install nativescript version 6.5.1 look like this npm i -g nativescript@6.5.1 But cmd return error: npm ERR! code EINTEGRITY npm ERR! sha512-bf7UQUo6n0c3Fxn5OXckpausCWjFg+qGLzN/LnaMsjF+9HYuSMbPPciWI6zPLu+KLnwjqwKzwPkozi/vxJYpvw== integrity checksum failed when using sha512: wanted sha512-bf7UQUo6n0c3Fxn5OXckpausCWjFg+qGLzN/LnaMsjF+9HYuSMbPPciWI6zPLu+KLnwjqwKzwPkozi/vxJYpvw== but got sha512-wyGWHP4AFW67EKazxHpKOCPu8cTK5mZSL5eXrLl0OFBoEY46wQLFgtVrPiBjrUp4rGg8fXnLUiRsoVSlgQAndw==. (15534 bytes)

Reproduction

No response

Relevant log output (if applicable)

No response

Environment

No response

Please accept these terms

rigor789 commented 1 year ago

Use a newer CLI version, preferably the latest - it should be backwards compatible with older projects (in most cases).

The issue is that some npm packages got moved/renamed over the years (6.5.1 was released 3 years ago) and cause shasums to mismatch. There's nothing we can do to fix the already released versions on the registry apart from publishing a new/patch version, however given these are more than 3 years old it's unlikely to happen.

A similar issue was reported for 6.8.0 and we did release a fix in 6.8.1 (https://github.com/NativeScript/nativescript-cli/issues/5719)

A possible workaround is provided in https://github.com/NativeScript/nativescript-cli/issues/5469

flipperlite commented 6 months ago

I also had an NS 6.8.1 project recently worked on. It can work if you install it local to your project and not globally. Some of the fix was taken from this issue. These instructions can work with global NS 8.x installed in parallel to your local project. I find that Node 14 is the most recent version that supports NS 6 without issue. Therefore, you need to have NVM installed to allow you to easily switch Node versions. I also have the alias line below added to my ~/.zshrc file to load on terminal start.

I would view this as a stop gap only as @rigor789 said and find a way to migrate ASAP the latest of NS. You'll not only live in dependency hell but also deal with new plugins that you want to use like @nativescript-community/perms not backwards compatible with NS6 and/or Node 14.

cd my-project (or whatever your project location is)
command -v nvm (confirm nvm works)
nvm install 14
nvm use 14
npm install --save-dev 'https://github.com/telerik/cli-table/tarball/v0.3.1.2'
npm install --save-dev 'https://github.com/NativeScript/marked-terminal/tarball/v3.1.1n'
npm install --save-dev nativescript@6.8.1
rm -rf node_modules package-lock.json
npm install
alias tns='nvm use 14 && ./node_modules/.bin/tns'
tns doctor
tns run ios
tns run android

Expanding that idea, you could have a Node version to match each NS version using alias. I believe the naming went from tns to ns at NS 7 but change accordingly. Your single machine can now support multiple Node and NS environments simultaneously.

alias ns6='nvm use 14 && ./node_modules/.bin/tns'
ns6 doctor
ns6 run ios
ns6 run android

alias ns7='nvm use 16 && ./node_modules/.bin/ns'
ns7 doctor
ns7 run ios
ns7 run android

alias ns8='nvm use 20 && ./node_modules/.bin/ns'
ns8 doctor
ns8 run ios
ns8 run android

You may find that your dependencies are broken too. I had to remove some old ones and use newer ones but not the most recent ones. For example, sass-loader version 8.x only works on Node 16 and breaks on Node 14 (my highest version of Node due to NS 6.x dependency) resulting in me using version 7.x below. Here's my package.json file with the latest versions that will work with NS 6.8.1.

    "nativescript": {
        "id": "com.foo.bar",
        "tns-android": {
            "version": "6.5.3"
        },
        "tns-ios": {
            "version": "6.5.6"
        }
    },
    "dependencies": {
        "@nstudio/nativescript-checkbox": "^1.0.0",
        "email-validator": "^2.0.4",
        "json-schema-defaults": "^0.4.0",
        "moment": "^2.28.0",
        "nativescript-iqkeyboardmanager": "^1.5.1",
        "nativescript-plugin-firebase": "^10.5.2",
        "nativescript-theme-core": "^1.0.4",
        "nativescript-ui-sidedrawer": "^6.0.0",
        "tns-core-modules": "6.5.27"
    },
    "devDependencies": {
        "babel-traverse": "6.26.0",
        "babel-types": "6.26.0",
        "babylon": "6.18.0",
        "cli-table": "https://github.com/telerik/cli-table/tarball/v0.3.1.2",
        "eslint": "^5.16.0",
        "lazy": "1.0.11",
        "marked-terminal": "https://github.com/NativeScript/marked-terminal/tarball/v3.1.1n",
        "nativescript": "^6.8.1",
        "nativescript-dev-webpack": "^1.5.1",
        "sass": "^1.71.1",
        "sass-loader": "^7.3.1",
        "should": "^11.1.2",
        "sinon": "^1.17.6",
        "tns-android": "6.5.3",
        "tns-ios": "6.5.6"
    }

My webpack.config.js with changes to SCSS compiler.

        module: {
            rules: [
                {
                    include: join(appFullPath, entryPath),
                    use: [
                        // Require all Android app components
                        platform === "android" && {
                            loader: "nativescript-dev-webpack/android-app-components-loader",
                            options: { modules: appComponents }
                        },

                        {
                            loader: "nativescript-dev-webpack/bundle-config-loader",
                            options: {
                                loadCss: !snapshot, // load the application css if in debug mode
                                unitTesting,
                                appFullPath,
                                projectRoot,
                                ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform)
                            }
                        },
                    ].filter(loader => !!loader)
                },

                {
                    test: /\.(js|css|scss|html|xml)$/,
                    use: "nativescript-dev-webpack/hmr/hot-loader"
                },

                { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" },

                {
                    test: /\.css$/,
                    use: "nativescript-dev-webpack/css2json-loader"
                },

                {
                    test: /\.scss$/,
                    use: [
                        { loader: "css-loader", options: { url: false } },
                        "sass-loader"
                    ]
                },
            ]
        },