zoukankan      html  css  js  c++  java
  • 项目中遇到的bug、问题总结

    1. Cannot set property 'captcha' of undefined

    在node项目中使用svg-captcha生成验证码报错

    captcha的代码,这里有一个session.captcha,检查app.js,发现session没设置

    exports.captcha = async(req, res, next) => {
      // 创建验证码
      const captcha = svgCaptcha.create()
      // 验证码文本
      req.session.captcha = captcha.text
      // 设置响应内容类型
      res.type('svg') // 使用ejs等模块时如果报错 res.type('html)
      res.status(200).send(captcha.data)
    }

    在app.js中加入session就可以了

    const express = require('express')
    const app = express()
    const session = require('express-session')
    
    app.use(session({
      secret: 'keyboard cat',
      resave: false,
      saveUninitialized: true
    }))

    这种错误一般是没定义属性引起的,检查一下使用的变量是否都有引入

    2.Module build failed: Error: ENOENT: no such file or directory, open 'xxxxxxxxx'

    切换分支后报找不到文件的错误

    这种情况一般是你切换分支后你的小伙伴修改了代码提交,你切回来之后就有可能读不出修改的文件

    这时候强制使用远程分支覆盖本地分支就可以了

    git fetch --all

    git reset --hard origin/master 这里是写你用来覆盖的分支名称,一般就是你当前所在的分支

    git pull

    3../node_modules/_css-loader@0.28.11@css-loader??ref--11-1!./node_modules/_postcss-loader@2.1.6@postcss-loader/lib??ref--11-2!./node_modules/_sass-loader@7.1.0@sass-loader/lib/loader.js??ref--11-3!./src/components/main/financingManagement/financing/creditFrom/from.scss Module build failed: undefined ^ Media query expression must begin with '(' in E:ProjectF2B_v3.0srccomponentsmainfinancingManagementfinancingcreditFromfrom.scss (line 3, column 3)

    在项目中引入scss文件报错,

    .financingManaFinancingForm_box {
    // 引入的时候没有加;号,css里面结尾一定要写;号
    @import 'src/assets/css/document.scss';
    .authfile_title {
    text-align: center;
    }
    }
     
    4.

    (function (exports, require, module, __filename, __dirname) { import { check, validationResult } from '_express-validator@5.3.1@express-validator/check';

    在项目中引入资源错误 ,在项目中是这样写的,这样会报错 

    import { check, validationResult } from '_express-validator@5.3.1@express-validator/check';
     
    如果引入多个资源, 必须使用const + require
    const { check, validationResult } = require('express-validator/check')
     
    5.
    TypeError: app.use() requires a middleware function
    启动项目报错
    在项目中多写了一个路由没有导出,启动时没有找到router的中间件
     
    const express = require('express')
    const questionCtrl = require('../controller/question.js')
    const router = express.Router()
    
    router
    .get('/questions/new', questionCtrl.showNew)
    
    module.exports = router  //router需要导出
     6.

    Refused to apply style from '<URL>' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled..

    在node项目中打开页面报错

    这是因为解析静态资源错误,检查一下静态资源的引入路径是否正确,然后重启一下项目,有时候不重启项目,这些解析资源的工作不会更改

     7.

     Cannot destructure property `user` of 'undefined' or 'null'

    页面报错

    这种是把一个对象结构赋值时报错的,原因是req.cookies没有值,

    let { user: cookieUser } = req.cookies
    let { user: cookieUser } = undefind // 这样会报错,对象的结构赋值需要确定是一个对象
     
    8.

    $ vue -V
    bash: vue: command not found

    找不到vue模块

    解决: npm install -g vue

    npm install -g vue-cli

    npm install -g vue-cli
    npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)

    安装vue-cli报错

    j解决: npm i -g coffeescript

    npm install -g vue-cli

    运行效果:

    $ vue -V
    2.9.6

    完成!

    9.

    vue create vuex-api

    vue create is a Vue CLI 3 only command and you are using Vue CLI 2.9.6.
    You may want to run the following to upgrade to Vue CLI 3:

    npm uninstall -g vue-cli
    npm install -g @vue/cli

    使用vue创建项目报错,create只支持vue cli 3版本,按照提示,卸载姐版本,npm uninstall -g vue-cli安装新版本 npm install -g @vue/cli

    npm install -g @vue/cli
    npm WARN deprecated cross-spawn-async@2.2.5: cross-spawn no longer requires a build toolchain, use it instead

    安装新版本vue-cli报错,

    解决方法: cnpm install -g @vue/cli

    重新运行

    $ vue create vuex-api
    ? Your connection to the default yarn registry seems to be slow.
    Use https://registry.npm.taobao.org for faster installation? (Y/n)

    创建项目成功!

  • 相关阅读:
    boost::asio在VS2008下的编译错误
    Java集合框架——接口
    ACM POJ 3981 字符串替换(简单题)
    ACM HDU 1042 N!(高精度计算阶乘)
    OneTwoThree (Uva)
    ACM POJ 3979 分数加减法(水题)
    ACM HDU 4004 The Frog's Games(2011ACM大连赛区第四题)
    Hexadecimal View (2011ACM亚洲大连赛区现场赛D题)
    ACM HDU 4002 Find the maximum(2011年大连赛区网络赛第二题)
    ACM HDU 4001 To Miss Our Children Time (2011ACM大连赛区网络赛)
  • 原文地址:https://www.cnblogs.com/steamed-twisted-roll/p/10506314.html
Copyright © 2011-2022 走看看