Node:找不到模块Error: Cannot find module
发布日期:2021-07-01 06:06:37
浏览次数:3
分类:技术文章
本文共 874 字,大约阅读时间需要 2 分钟。
问题
安装完模块
npm install -g crypto-js
导入模块报错
var CryptoJS = require("crypto-js");// 运行报错 Error: Cannot find module 'crypto-js'
解决
查看安装路径
$ npm prefix -g # node安装路径/Users/xxx/.nvm/versions/node/v10.16.0$ npm -g root # 查看依赖安装路径/Users/xxx/.nvm/versions/node/v10.16.0/lib/node_modules
通过 module.paths
查看模块查找列表,发现都没有
console.log(module.paths)[ '/Users/xxx/Desktop/node_modules', '/Users/xxx/node_modules', '/Users/node_modules', '/node_modules' ]
解决
方案1:直接使用模块绝对路径
var CryptoJS = require("/Users/xxx/.nvm/versions/node/v10.16.0/lib/node_modules/crypto-js");
方案2:将node_modules 路径添加到模块查找路径列表
module.paths.push("/Users/xxx/.nvm/versions/node/v10.16.0/lib/node_modules")var CryptoJS = require("crypto-js");
方案3:添加NODE_PATH环境变量
$ vim ~/.bash_profile# nodepathexport NODE_PATH="/Users/xxx/.nvm/versions/node/v10.16.0/lib/node_modules"
sublime下使用方案3,没有成功,文件~/.bash_profile
的变量都没有导入
参考
转载地址:https://pengshiyu.blog.csdn.net/article/details/100168155 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
感谢大佬
[***.8.128.20]2024年04月10日 11时53分42秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
内存分配(mallloc,calloc,realloc,new)
2019-05-01
使用 Minidumps 和 Visual Studio .NET 进行崩溃后调试
2019-05-01
struts返回xml数据例子
2019-05-01
内存对齐详解
2019-05-01
秋招总结(一)-C++归纳
2019-05-01
秋招总结(三)-操作系统归纳
2019-05-01
LINUX CP命令详解
2019-05-01
source insight快捷键及使用技巧
2019-05-01
映 射 ALT 键
2019-05-01
vim使用快捷键F4生成文件头注释、F5生成main函数模板、F6生成.h文件框架模板
2019-05-01
OV5620的视频驱动
2019-05-01
C++中两个类交叉定义或递归定义的解决办法
2019-05-01
记一次Hive 行转列 引起的GC overhead limit exceeded
2019-05-01
OpenGL ES八 - 交叉存取顶点数据
2019-05-01
crontab定时任务写法
2019-05-01
nginx: [emerg] unknown directive "if($remote_addr" in /usr/local/tools/nginx/conf/nginx.conf:57
2019-05-01
module pip has no attribute main问题解决
2019-05-01
LeetCode 134.Gas Station (加油站)
2019-05-01
Python之命名元组 (namedtuple)
2019-05-01