uni-app ubuntu在vue-cli创建项目时提示Missing script: "dev:h5"

uni-app ubuntu在vue-cli创建项目时提示Missing script: “dev:h5”

示例代码:

在my-project里面的node_modules只有两个文件夹@dcloudioregenerator-runtime

package.js文件

{
  "name": "my-project",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@dcloudio/uni-helper-json": "*",
    "regenerator-runtime": "^0.12.1"
  },
  "devDependencies": {
    "@babel/runtime": "~7.12.0",
    "@dcloudio/types": "*",
    "@dcloudio/vue-cli-plugin-hbuilderx": "^2.0.0-22420190823018",
    "@dcloudio/vue-cli-plugin-uni": "^2.0.0-22420190823018",
    "@dcloudio/vue-cli-plugin-uni-optimize": "^2.0.0-22420190823018",
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "mini-types": "*",
    "miniprogram-api-typings": "*",
    "postcss-comment": "^2.0.0"
  }
}

postcss.config.js

const path = require('path')
module.exports = {
  parser: require('postcss-comment'),
  plugins: [
    require('postcss-import')({
      resolve (id, basedir, importOptions) {
        if (id.startsWith('~@/')) {
          return path.resolve(process.env.UNI_INPUT_DIR, id.substr(3))
        } else if (id.startsWith('@/')) {
          return path.resolve(process.env.UNI_INPUT_DIR, id.substr(2))
        } else if (id.startsWith('/') && !id.startsWith('//')) {
          return path.resolve(process.env.UNI_INPUT_DIR, id.substr(1))
        }
        return id
      }
    }),
    require('autoprefixer')({
      remove: process.env.UNI_PLATFORM !== 'h5'
    }),
    require('@dcloudio/vue-cli-plugin-uni/packages/postcss')
  ]
}

操作步骤:

/www/constellation # npm -v
8.1.0
/www/constellation # node -v
v16.13.0
/www/constellation # cat /proc/version
Linux version 5.11.0-34-generic (buildd@lgw01-amd64-011) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #36~20.04.1-Ubuntu SMP Fri Aug 27 08:06:32 UTC 2021
/www/constellation #  npm get registry
https://registry.npm.taobao.org/
/www/constellation # npm install -g @vue/cli
...
changed 944 packages in 24s
...
/www/constellation # vue create -p dcloudio/uni-preset-vue my-project
Fetching remote preset dcloudio/uni-preset-vue...
...

预期结果:

如何才能成功的有运行 npm run dev:h5

实际结果:

/www/constellation/my-project # npm run dev:h5
npm ERR! Missing script: "dev:h5"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR!   npm run

bug描述:

系统是在ubuntu 20.04

/www/constellation/my-project # yarn serve
yarn run v1.22.15
error Command "serve" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

/www/constellation/my-project # npm run dev:h5
npm ERR! Missing script: "dev:h5"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR!   npm run

更多关于uni-app ubuntu在vue-cli创建项目时提示Missing script: "dev:h5"的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于uni-app ubuntu在vue-cli创建项目时提示Missing script: "dev:h5"的实战教程也可以访问 https://www.itying.com/category-93-b0.html


这个问题是由于项目依赖包没有完整安装导致的。从你的package.json文件可以看出,项目依赖了多个@dcloudio相关的包,但node_modules目录中只有两个文件夹,说明npm install没有执行成功。

解决方案:

1. 重新安装依赖

进入项目目录,删除node_modules和package-lock.json(或yarn.lock),然后重新安装:

cd /www/constellation/my-project
rm -rf node_modules package-lock.json
npm install

2. 检查网络和镜像源

你使用的是淘宝镜像,但可能某些包下载失败。可以尝试:

# 清除npm缓存
npm cache clean --force

# 使用cnpm(如果npm install仍然失败)
npm install -g cnpm --registry=https://registry.npmmirror.com
cnpm install

3. 验证安装结果

安装完成后,node_modules目录应该有完整的依赖包,package.json中定义的脚本也会生效。可以通过以下命令查看可用脚本:

npm run

正常应该能看到类似这样的输出:

Scripts available in my-project via `npm run-script`:
  dev:app-plus
  dev:h5
  dev:mp-alipay
  dev:mp-baidu
  dev:mp-weixin
  build:app-plus
  build:h5
  build:mp-alipay
  build:mp-baidu
  build:mp-weixin

4. 如果问题依旧

可能是vue-cli创建项目时模板下载不完整。建议:

# 删除项目重新创建
cd /www/constellation
rm -rf my-project
vue create -p dcloudio/uni-preset-vue my-project
cd my-project
npm install
回到顶部