-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invoking sam local invoke returns an Unable to import module 'index': Error #208
Comments
The root problem seems to be SELinux. I tried to run lambci/lambda:nodejs6.10 container directly in example dir as it described at lambci repo: |
@zhabba I'm invoking the said function on a windows machine is there anyway I can identify where the container is located directly by default in a windows machine? so I can run the commend you have specified? I've tried running your command in the same dir where the files are located
and it resulted to this
I am running on a windows 10 machine |
@kyeljmd please change "$PWD" to actual path where you're running container as error suggests: |
Any Solution. I have the same issue. Error Message:
I'm tried to run HelloWorld sample. |
@francistec first, if you're running command under the Windows change "$PWD" to actual absolute path to directory with your code, like: C:\what\ever\aws-sam-local\samples\hello-world\node. And second, pass JSON as a string: "{"name":"Bob"}". |
@zhabba, I'm have the same issue. I'm running on Windows 10 with Cygwin.
Docker versions:
NPM Version: 3.10.10 Running this same code on a Linux server works with or without
It looks like it might be a folder permissions issue but I'm stumped. I was following along with this tutorial if that helps any. |
Did it work for anyone on Windows? {"errorMessage":"Cannot find module '/var/task/index'","errorType":"Error","stackTrace":["Function.Module._load (module.js:417:25)","Module.require (module.js:497:17)","require (internal/module.js:20:19)"]} |
same here |
Maybe I'm on the different case but I've resolved the similar I'm using the Windows subsystem for Linux but running Docker on Windows and using Docker on Linux by mapping the port. On WSL, The problem was that this So I re-mounted the And I've invoked my function like this: And it worked! |
Same problem here with the hello-world sample, Unable to mount the volume... I tried all of the above solutions, none of them worked. Using windows 10. |
FWIW I recently started having this issue trying to test a function that was mounting fine previously. I reset docker to factory defaults, and when I next ran sam local was prompted to allow the drive to be shared and had to enter my password, now it's working. |
@Stubie17 That resolved my problems with the HelloWorld sample, thanks. |
Same issue, my config is: |
@JonathanJonathanJonathan @Stubie17 factory default reset didn't work for me. |
@Kivol Thank you! I was banging my head against the wall yesterday on this with WSL. So glad you posted your solution. 🙏 |
For everyone using Windows 7 and Docker Toolbox (Docker version 18.01.0-ce, build 03596f51b1):
You can also use |
FWIW @zhabba 's suggestion to use absolute paths fixed it for me |
Hi i am seeing the same error while running the command "sam local invoke "HelloWorld" -e input/events.json " from the directory where my index.js and template.yml are located on an amazon linux EC2 instance.
I would greatly appreciate any help towards resolving this. Thanks in advance! |
This can also happen when you have a complication error in index.js. A bad import or perhaps not installing a node module necessary for index.js. The error message acts as if it can't find it, but in reality, it is because complication failed. |
@Stubie17 Thanks!! Also Windows 10. I just had to reset my credentials for the shared drive. |
Hi I am using Ubuntu-14.04. Using Docker version
SAM Local I am trying to run the HelloWorld template and getting the following error:
Even with docker command:
I am getting nowhere with the solutions above. Please help. |
I had the same problem: We want to include a self-made npm module. I just played around and after moving a class within the module to index.ts, publish it, run npm install and then sam local again, everything works fine. Well this is not a general insight or a general solution, but it seems (for our use-case at least) this would solve the problem: bind every typescript class and interface to a single index.js during compile time before publishing the npm module. |
To expand upon this, if docker is set to run with the --selinux-enabled flag in /etc/sysconfig/docker, the (lack of) SELinux labeling on the host directory being passed to the container as a volume will cause the underlying docker container to be unable to read the files. You can address this without disabling SELinux protection in Docker, however! To work around this issue on SELinux-enabled systems, tag your lambda's working directory on the docker host with the svirt_sandbox_file_t tag: |
I just have the same problem running the python "hello world" sample on a brand new win 10 machine. the quickest fix based on based on @Kivol comments was to remap my c drive in VirtualBox |
@Stubie17 thanks. This fixed my issue on Windows as well. To elaborate, instead of completely resetting Docker, you can optionally go to Settings > Shared Drives and un-check your drive. Once you run |
Thanks everyone for the instructions to fix this issue. It is not a SAM CLI bug but a mis-configuration in the Docker sharing settings. Hence closing the issue |
doing
|
Instead of resetting Docker to factory defaults you can select "Reset credentials" under the "Shared Drives" tab in Docker Settings. That should force a re-authentication using your current Windows user/pass. This resolved my problem. |
I was following along AWS's quick start tutorial and was pretty confused by the unable to import module 'app' error, @Stubie17 's solution solved the problem (I just unchecked and rechecked the shared drive) |
This works for me! and make sure turn off your firewall if you have it in your OS. |
Just a note on this. I found this started happening on Windows and didn't make the connection to my recent password change. The fix, as above, is to open the Docker settings, unshare Windows C drive, and then when it's reshared by Docker, it will prompt you for a password. |
Thank you @Kivol , I mounted again my C and its working !! thanks 🙏 |
I'm trying to play with the Hello-world example located in the samples of the repository. However upon invoking
sam local invoke "HelloWorld" -e event.json
inside the directory where the index, template.yml and is located.it automatically returns the ff:
START RequestId: e50a858c-69d8-16fc-02d3-70199542bc48 Version: $LATEST Unable to import module 'index': Error at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) END RequestId: e50a858c-69d8-16fc-02d3-70199542bc48 REPORT RequestId: e50a858c-69d8-16fc-02d3-70199542bc48 Duration: 31.25 ms Billed Duration: 0 ms Memory Size: 0 M
The text was updated successfully, but these errors were encountered: