Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node module-alias Error: Cannot find module '@src/utils/constants'

I'm running mocha tests and I recently upgraded to the newest version of the ask-cli. I ran the tests again and I'm now receiving this module error. I've npm installed src and utils to no avail. From what I've read it's possible module-alias does not support @src paths.

I'm calling this command:

$ ask api simulate-skill -l en-US -t "start my day" -s amzn1.ask.skill.XXXXXXXX-4156-4ca0-b14e-XXXXXXXXXXXX

Update: this seems to be an issue with the ask-cli which uses

const CONSTANTS = require('@src/utils/constants'); The @src should find the source of the node package but this @src is not used in any other packages I could find. All other packages seem to use ../../ so that's likely while module-alias does not find anything bc it doesn't know how to route this new syntax

Does anyone know of this new @src syntax and if there is a npm module for helping route it?

Which worked for ask-cli 1.1.6 but I upgraded to 1.7.2 for new functionality.

Error: Cannot find module '@src/utils/constants'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._resolveFilename (/Users/calebgates/WebstormProjects/AutomatedUtteranceTesting/node_modules/module-alias/index.js:49:29)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/calebgates/WebstormProjects/AutomatedUtteranceTesting/node_modules/ask-cli/lib/commands/init/index.js:1:81)
    at Module._compile (module.js:652:30)
    at Module.replacementCompile (/Users/calebgates/WebstormProjects/AutomatedUtteranceTesting/node_modules/nyc/node_modules/append-transform/index.js:58:13)
    at module.exports (/Users/calebgates/WebstormProjects/AutomatedUtteranceTesting/node_modules/nyc/node_modules/default-require-extensions/js.js:8:9)
    at Object.<anonymous> (/Users/calebgates/WebstormProjects/AutomatedUtteranceTesting/node_modules/nyc/node_modules/append-transform/index.js:62:4)
module.js:549
like image 676
Caleb Gates Avatar asked May 06 '19 20:05

Caleb Gates


People also ask

How to fix Cannot find module or its corresponding Type declarations?

The "Cannot find module or its corresponding type declarations" error occurs when TypeScript cannot locate a third-party or local module in our project. To solve the error, make sure to install the module and try setting moduleResolution to node in your tsconfig. json file.

Can not find module error?

The Cannot find module error is a common error that usually happens when dependencies are not installed. Once you install your dependencies and ensure that the paths are correct, you can resolve the error and run your application successfully.

Can't find module after npm install?

If you have run the npm install command before, then it's possible that the installation of the module is incomplete or corrupted. Delete the node_modules/ folder using the rm -rf node_modules command, then run npm install again. That may fix the issue.


1 Answers

I solved this by including the ask-sdk in my local project's dependencies.

like image 62
btburton42 Avatar answered Sep 18 '22 20:09

btburton42