項目中遇到的bug、問題總結

1. Cannot set property 'captcha' of undefinedcss

在node項目中使用svg-captcha生成驗證碼報錯html

captcha的代碼,這裏有一個session.captcha,檢查app.js,發現session沒設置vue

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就能夠了node

const express = require('express')
const app = express()
const session = require('express-session')

app.use(session({
  secret: 'keyboard cat',
  resave: false,
  saveUninitialized: true
}))

這種錯誤通常是沒定義屬性引發的,檢查一下使用的變量是否都有引入git

 

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

切換分支後報找不到文件的錯誤vue-cli

這種狀況通常是你切換分支後你的小夥伴修改了代碼提交,你切回來以後就有可能讀不出修改的文件express

這時候強制使用遠程分支覆蓋本地分支就能夠了npm

git fetch --all api

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:\Project\F2B_v3.0\src\components\main\financingManagement\financing\creditFrom\from.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)

建立項目成功!

相關文章
相關標籤/搜索