Within the dependencies directory, there exists a module named foo
:
import foo from '../dependencies/foo'; // This import statement works as intended
The challenge arises when attempting to import from a different path due to deployment in an AWS dependency layer:
import foo from '/opt/dependencies/foo';
However, this results in the following error message:
Error: Cannot locate module '/opt/dependencies/foo' or its corresponding type declarations.ts(2307)
An alternative solution would be using require()
, but it prompts a warning advising to use an import
statement instead:
const foo = require('/opt/dependencies/foo');
What steps can be taken to bypass this error while maintaining the /opt path?