TypeError [ERR_INVALID_ARG_TYPE]:“ id”参数必须为字符串类型。收到的类型对象

时间:2019-10-10 21:56:31

标签: javascript mysql node.js requirejs

我正在尝试使用require.js将我的应用程序连接到MySql数据库。但是出现以下错误:

  

抛出新的ERR_INVALID_ARG_TYPE(name,'string',value);

我的服务器端代码如下:

mijs.js

  `require(["mysql"],function(mysql) {
    var connection = mysql.createConnection({
       host: "localhost",
       user: "root",
       password: 'XXXX',
       database: 'XXXXXXX',
       port: 3306
    });
connection.connect(function(error){
   if(error){
      throw error;
   }else{
      console.log('Conexion correcta.');
   }
});
});`

错误消息是:

internal/validators.js:112
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received type object
←[90m    at validateString (internal/validators.js:112:11)←[39m
←[90m    at Module.require (internal/modules/cjs/loader.js:831:3)←[39m
←[90m    at require (internal/modules/cjs/helpers.js:74:18)←[39m
    at Object.<anonymous> (C:\xampp\htdocs\Middleware\Temas\mijs.js:3:1)
←[90m    at Module._compile (internal/modules/cjs/loader.js:945:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:798:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:711:12)←[39m
←[90m    at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)←[39m
←[90m    at internal/main/run_main_module.js:17:11←[39m

0 个答案:

没有答案