Nodejs Error: Cannot find module 当前文件夹下的模块

当执行如下代码是,nodejs 报错 Cannot find module(a.js 为当前文件夹下的同级文件)

var x = require("a.js") 

修改为 ./ 后正常

var x = require("./a.js") 

或者执行node命令入口时添加 (index.js 为主入口文件)

NODE_ENV . node index.js

主要目的:将当前文件夹”.” 添加到node 查找模块的路径中

参考文档:https://gist.github.com/branneman/8048520

原文如下:
4.2. Only while executing node

This solution will not affect your environment other than what node preceives. It does change your application start command.

Start your application like this from now on:
Linux: NODE_PATH=. node app
Windows: cmd.exe /C “set NODE_PATH=.&& node app”

(On Windows this command will not work if you put a space in between the path and the &&. Crazy shit.)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于问题一,报错信息是"Error: Cannot find module 'D:\project***\node_modules_@[email protected]@@vue\cli-service\bin\vue-cli-service.js'"。处理这个问题的方法是检查你的项目文件夹中是否存在该路径下的vue-cli-service.js文件。如果文件确实不存在,请尝试重新安装依赖或恢复项目文件。 对于问题二,报错信息是"Module parse failed: Unexpected character '�' (1:0) You may need an appropriate loader to handle this file type. (Source code omitted for this binary file)"。这个错误通常是由于无法正确解析文件类型引起的。你可能需要使用适当的加载器(loader)来处理这种文件类型。检查你的webpack配置文件,确保已经正确配置了相关加载器。 关于你的问题"Error: Cannot find module 'node-windows'",你可以尝试使用以下方法解决。根据引用中的信息,你可以在Windows系统中使用命令行来启动你的应用程序。打开命令提示符(cmd.exe)并执行以下命令:"set NODE_PATH=.& node app"。这将设置NODE_PATH环境变量并启动你的应用程序。这样做可以解决找不到'mode-windows'模块的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Error: Cannot find module 等问题 - npm篇](https://blog.csdn.net/qq_40968685/article/details/115693385)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [Nodejs Error: Cannot find module 当前文件夹下的模块](https://blog.csdn.net/ISaiSai/article/details/77934854)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值