Node.js -- Modules

  • 文件模块一一对应

引入模块

  • require用于从外部获取一个模块
    • 引入当前文件夹内的hello.js
var hello = require('./hello');

导出模块

  • exports用于把对象公开
    • 公开文件中的 'world' function:【hello.js】exports.world = function() {...}
      • 使用 world:require('hello'); hello.world() //先import文件,再使用function
    • 直接公开一个对象:【hello.js】function Hello() {...} module.exports = Hello;
      • 直接使用hello对象:require('hello'); hello.xxx

**前者require返回的是exports对象,world是其中的成员函数;后者返回的hello对象,也就是我们要的东西

模块加载

文件模块缓存 --> 原生模块 --> 文件系统

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ERROR Failed to compile with 48 errors 上午10:53:54 These dependencies were not found: * core-js/modules/es.array.push.js in ./node_modules/.store/@[email protected]/node_modules/@babel/runtime/helpers/esm/objectSpread2.js, ./node_modules/.store/[email protected]/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/.store/[email protected]/node_modules/babel-loader/lib!./node_modules/.store/[email protected]/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/.store/[email protected]/node_modules/vue-loader/lib??vue-loader-options!./src/components/HeaderSearch/index.vue?vue&type=script&lang=js& and 29 others * core-js/modules/es.error.cause.js in ./node_modules/.store/@[email protected]/node_modules/@babel/runtime/helpers/esm/regeneratorRuntime.js, ./node_modules/.store/[email protected]/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/.store/[email protected]/node_modules/babel-loader/lib!./node_modules/.store/[email protected]/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/.store/[email protected]/node_modules/vue-loader/lib??vue-loader-options!./src/layout/components/Navbar.vue?vue&type=script&lang=js& and 5 others * core-js/modules/es.object.proto.js in ./node_modules/.store/@[email protected]/node_modules/@babel/runtime/helpers/esm/regeneratorRuntime.js * core-js/modules/es.regexp.dot-all.js in ./node_modules/.store/[email protected]/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/.store/[email protected]/node_modules/babel-loader/lib!./node_modules/.store/[email protected]/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/.store/[email protected]/node_modules/vue-loader/lib??vue-loader-options!./src/components/ThemePicker/index.vue?vue&type=script&lang=js&, ./node_modules/.store/[email protected]/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/.store/[email protected]/node_modules/babel-loader/lib!./node_modules/.store/[email protected]/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/.store/[email protected]/node_modules/vue-loader/lib??vue-loader-options!./src/layout/components/Navbar.vue?vue&type=script&lang=js& and 2 others * core-js/modules/web.url-search-params.delete.js in ./src/utils/request.js * core-js/modules/web.url-search-params.has.js in ./src/utils/request.js * core-js/modules/web.url-search-params.size.js in ./src/utils/request.js * qs in ./src/utils/request.js * svg-baker-runtime/browser-symbol in ./src/icons/svg/user.svg To install them, you can run: npm install --save core-js/modules/es.array.push.js core-js/modules/es.error.cause.js core-js/modules/es.object.proto.js core-js/modules/es.regexp.dot-all.js core-js/modules/web.url-search-params.delete.js core-js/modules/web.url-search-params.has.js core-js/modules/web.url-search-params.size.js qs svg-baker-runtime/browser-symbol怎么解决如何安装
最新发布
07-21

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值