Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

require statements for local node_modules is not working in truffle exec #383

Closed
1 task done
shota-takizawa opened this issue Mar 29, 2017 · 2 comments
Closed
1 task done
Assignees
Projects

Comments

@shota-takizawa
Copy link
Contributor

shota-takizawa commented Mar 29, 2017


Issue

Can't use local installed node_modules in external scripts and migration files.
This issue is same as #255 and #259.
requre statements for global node_modules is fixed by Truffle 3.1.10, but local is not.

Steps to Reproduce

Run truffle exec ext/sample.js in following project.
Truffle is installed global, local_node_module is only local.

/home/user/myProject/
.
+ build/
+ contracts/
+ ext/
    + sample.js # <- contains `require('local_node_module')` statement
+ migrations/
+ node_modules/
    + local_node_module/
+ test/
+ truffle.js

Results

Error: Cannot find module 'local_node_module'

Cause

Truffle looks only /home/user/myProject/ext/node_modules, but expected location is /home/user/myProject/node_modules.

Node.js looks parent directory if can not find node_modules.
https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders

This behavior is not implemented on Truffle.

Environment

  • Operating System: Ubuntu 16.04.2 LTS
  • Truffle version: 3.1.10

Pull Request

trufflesuite/truffle-require#1

@travs
Copy link

travs commented Apr 19, 2017

I have the same problem; temporary fix is to point to it with a relative path e.g.

require('../node_modules/express')

Looking forward to the next release 😄

@tcoulter
Copy link
Contributor

This bug is fixed, but we never pushed out a new version. Added tests here. Will push out a new version of Truffle with the fix once the changes are approved. trufflesuite/truffle-require#6

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
v3.3.0
Staged
Development

No branches or pull requests

4 participants