-
-
Notifications
You must be signed in to change notification settings - Fork 536
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
Allow import of directories with index.ts and import of files without extension #1198
Comments
I'm so accustomed to people omitting information from the bug report template, that I forgot you're using the "feature request" template instead. My apologies; responding to lots of low-effort bug reports tends to wear on a person over time. But anyway, yes this should work. Can you share the exact |
Sure, here are the information:
I am invoking it like this:
I tried adding the flag:
Other way round:
I am not using it together with vite in that sense. I just proxy a few requests to the server but the server wouldnt even start. |
This is the version where I removed all direct directory imports in the server file. However, imported files still use the syntax. |
Thanks, this information makes it easy to point out the proper solution. As you probably know from node's documentation, The correct invocation is The error you're getting:
...happens because node is trying to execute the file as CJS instead of ESM. Node has its own rules for when it decides to run a file as ESM and when as CJS. It will either use file extension or package.json. In our case, because we're using the TypeScript compiler which has not implemented any sort of Documentation is here: Once you tell node to execute your files as ESM, this should work. |
@cspotcode adding the module type to the package.json is one of the first things I did. Omitting it leads to the same error when the flag is omitted, too. However, adding it, leads to error no1 while adding the flag gives us back error no3. So even with type: module it handles some module as cjs PS: didnt know the node parameter thing yet. Thanks for that! |
Could be that another package.json exists and does not have the necessary flag, causing node to load certain files as CJS. Here is a reproduction showing that this feature does work as intended. If you're able to modify that reproduction to demonstrate the issue, then we can investigate further. Modifying the reproduction means forking and submitting a pull request to ts-node-repros, which will be executed by Github Actions. |
Omg, I finally found the issue. I was importing a ts module whose package.json did not have the type correctly set. It works now - well it errors - but it works. Thank you very much for pointing me in the right direction! |
Great, glad to hear it's working!
…On Mon, Jan 18, 2021, 5:47 PM Ulrich-Matthias Schäfer < ***@***.***> wrote:
Closed #1198 <#1198>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1198 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35OAZCZAD4TUZMWCQAJ3S2S3AZANCNFSM4WH2X6LQ>
.
|
Desired Behavior
This should work
Is this request related to a problem?
I am using ts-node together with vite. Vite natively supports typescript and imports as requested.
I would like to share code on both client and server but the client side code uses directory imports and imports without file extension. So it wont run.
Alternatives you've considered
I tried to use
--experimental-specifier-resolution=node
but it doenst seem to work together with a loader (which makes sense).If someone has a quickfix for me, that would also do the trick for now
The text was updated successfully, but these errors were encountered: