Skip to content
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

Importing Functions from local files with dynamic paths #295

Closed
nairol203 opened this issue Apr 3, 2023 · 1 comment
Closed

Importing Functions from local files with dynamic paths #295

nairol203 opened this issue Apr 3, 2023 · 1 comment
Labels
question Further information is requested

Comments

@nairol203
Copy link

Bug Report

I am trying to dynamically import a function with the filename given in a function argument.
This are my approaches and outcomes:

First approach: require()

Line of Code:
const file = await require(`./${fileName}`);
And the compiler options:

"module": "ESNext",
"target": "CommonJS",
"esModuleInterop": true,

This is giving me this error:

ReferenceError: require is not defined
    at (api/test.js:116:87)
    at (api/test.js:116:24)
    at (api/test.js:130:28)

However, when i trying the same with an static path and not the variable in the path, it works, no errors.
const file = await require('./test');

Second approach: import()

Line of Code:
const file = await import(`./${fileName}`);
const file = await import('./test');
And my typescript compiler options:

"module": "es2020",
"target": "es2020",
"esModuleInterop": true,

But that is giving me this error, with the variable in the path and also without.

Error: internal error
    at (api/test.js:87:52)
    at (api/test.js:101:34)
    at (api/test.js:23:11)
@Kikobeats
Copy link
Member

Sorry, that is not supported and not expected to be supported.

You should to get your code ready before passing it to Edge Runtime, like this example:
https://edge-runtime.vercel.app/packages/runtime#usage

🙂

@Kikobeats Kikobeats added the question Further information is requested label Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants