-
-
Notifications
You must be signed in to change notification settings - Fork 740
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
Errors resolving node dependencies when building with Angular #1441
Comments
I think this may be a different problem with the Angular builder. In the issue you link to, the comments suggest the relevant package exports different scripts for Node and for the browser. That's not something markdownlint does. (To be clear, there is a Webpack configuration that runs in the browser (see ./demo), but this is not exported, so it is not causing confusion. However, the existence of this does prove markdownlint can be successfully bundled to run in the browser.) The issue you report highlights imports with the "node:" prefix which is not universally supported by tooling in my experience. (I have to do something special for it for Webpack, for example.) My guess is this is what Angular is tripping up on, but again the fact that it works in some of their tools demonstrates there are not problems with how markdownlint is configured. Possible good news for your scenario is that I will publish a new version of markdownlint in a day or two which has been converted from CommonJS to ESM and that may help with the Angular problem. (However, the "node:" prefix is still in use as it is recommended by the Node team.) I will leave this issue open as a reminder, but everything I've seen so far suggests a bug in Angular tools which I'm not able to comment on without a better understanding. |
Thinking about this a little more, what I'm guessing may be going on is that Angular is trying to bundle a Node application with Node dependencies to run in the browser but they are NOT stubbing out the relevant Node dependencies. Instead, they expect every package to provide a browser export that does that for them. If so, I expect problems like this are fairly common with this approach. As I wrote above, markdownlint CAN be bundled for the browser by stubbing out its Node dependencies and a proof/example/template for doing so can be found here: |
Yes it seems that when using their builder with the But it would be nice if you also provided an entry point in your library distribution specifically for browser use, instead of having to manually build this ourselves. One that would allow just importing the module in a JS/TS file and building like many other libraries have. For now I'm going to see if there is a way to tell the Angular builder to stub our certain dependencies. Otherwise, I may have to do some manual work to include the required scripts like in your demo project. |
I managed to get it working in Angular using the following:
then later in the code i can use it like:
This seems to work so far, however, the disadvantage of this is that the created JS bundle (
That actually works with |
Great, thank you for the update! I've been thinking about this some more and I have an idea that might work for your scenario without forcing too many other weird changes. I don't think it will make the current release, but I'll probably play around with this soon. |
That's good news. I would appreciate it if you could let me know in this thread when the new solution is available so I can update my project with a better solution. I can also test it and give you feedback if needed. |
…by stubbing-away Node imports (refs #1441).
@kareldonk, I have something for you to try in the branch For reference: efefc6e |
@DavidAnson I tried it and it works. Now i can put the following at the top of the TS file:
Then later in the code I can do:
I did have to change the settings in my Typescript
Specifically, the But now both Angular build methods work ( Let me know if you need more info. Do you have an idea when this might be released? |
Great news! I just posted a release converting to ESM (that's why your imports changed), so I wouldn't normally release again for a little while. I might do this as a one off soon, depending on if there's fallout from the conversion. |
Thanks, I'd appreciate an update in this thread when you release it :) |
@kareldonk, could you please try again using |
I tried it and when it comes to building and using the types it still works. One thing that I do want to mention is that, also with the previous test version above, in VSCode the editor is not able to automatically detect the markdownlint types. For example, if you are in a new TS file, and you have not imported anything yet from markdownlint, then typing the below line will not make it suggest an import from markdownlint:
On that line, VSCode will put red squiggly lines below There is another problem however. With this version, I am getting an exception when trying to lint the following text:
Error:
This is thrown in the function
|
Thank you for the update! I'll see if I can reproduce the automatic import behavior you mention. I agree it is not a blocker, but I wonder if it is related to the extra level of indirection I have here because of subpath exports (not super common). I couldn't see another way without involving a tool to generate the declaration file. I'm curious if you know if this previously worked with markdownlint because all published versions so far have a single, self-contained declaration file. Regarding the crash, I will definitely look into that. I can tell from the message that it's coming from the micromark parser which has not changed. So either that problem exists in published versions of markdownlint (possible, but seems unlikely given how simple your scenario is), or it got introduced somehow when I converted to ESM (but how?), or it got introduced when I added the browser export (unlikely in my mind). Your example works fine in the current release (as tested using the browser demo link below), so I'm inclined to think this is new somehow and the ESM conversion is my guess. |
Oh, wait! The message you are seeing is a development-time message that goes away for release scenarios. It definitely could have existed all along because I know micromark has issues in this area since I've reported a few of them. :) It's probably not catastrophic and it has probably been there for a while. What's different now is that I used to need to bundle micromark for reuse because it is ESM and the library was CommonJS, but now that's no longer necessary and your workflow is giving you the development version. I can't tell much more from my phone right now, but if your tooling allows you to select production vs. development (as Webpack does), please try switching to production and see if this goes away. I'm not sure what to do about it (if anything), but it's great to understand this implication. |
Confirmed: The Assertion above is because you're running the "development" bits for I'm going to look at doing the |
I am NOT able to reproduce the type issue you report:
Then
If this is still happening for you, please let me know what to change about my steps to reproduce it. Thank you! |
In branch |
You're right about the exception being thrown in the development build. I switched to production build for Angular and do not get the exception there. As for importing the types automatically in VSCode, I tried it again with the So I guess everything is resolved now. :) |
@kareldonk, available in |
Thanks! |
@DavidAnson Thanks! Works in prod. |
The 'modern' builders such as used in Angular have trouble resolving node dependencies that are included in markdownlint.
There is an issue that describes the probem here: angular/angular-cli#27425
It works with the
ng serve
command because that uses a different way to bundle the files, but not withng build
.According to the Angular devs, this is because the markdownlint "package does not expose its browser bundle to modern ESM bundlers."
It would be nice to have that support.
The text was updated successfully, but these errors were encountered: