I’m having a lot of trouble getting the npm to work… I know there’s a CDN script tag I can use, but I’d like to understand how to get these npms to work as well.
I installed marked locally via npm install --save marked
I then put import { marked } from "marked"; at the top of my page.
However, when I try and use marked.parse(), it throws an error and says: Uncaught TypeError: Failed to resolve module specifier "marked". Relative references must start with either "/", "./", or "../".
when I add / or ./ it then says: GET http://127.0.0.1:5500/marked net::ERR_ABORTED 404 (Not Found)
Sorry, I’m really struggling with these npm installs.
Sorry, I just started using stacckblitz 2 days ago… Not sure how to share things and whatnot.
But I copy/pasted the html, js, & package.json code to their respective files in there. Hopefully this is what you needed.
I’ll eventually be using React yes.
Was just tinkering with npm’s in vscode, trying to install some and get them to work…
Didn’t even know that I had to import them differently for React. What a complicated little task this is ending up being. Or did you just mean the way I was utilizing markdown wouldn’t be the way I would in React?
I think you are just a little too curious, which usually isn’t a bad thing. It does however make things more complicated as you have to learn about too many different things all at once.
So the issue is you are sort of mixing Node and the Browser. In this case, the dependency (markedjs) does have an ESM build which can be used in the browser but the way you import modules in plain JS is different from a Node app.
Uncaught TypeError: The specifier “marked” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “…/” or “/”.
You also have to check the specific dependency and which environment it is meant to be used in. There are plenty of libraries you can install using npm that don’t run in the browser at all.
I think you’re definitely right about the curiosity, I’m getting too side tracked with these details that I should be worrying about after I actually know how to code! I’ve probably wasted 8 hours on tinkering with this stuff, instead of just doing the project.
Anyhoot! Thank you for explaining that. I bookmarked your response and I’m going to go through it again in the future when I have a better understanding of everything. I honestly don’t think I even have the knowledge base to understand a lot of those concepts right now anyway. I naively though the npm universe was going to be more simple than it is, I definitely underestimated it’s complexity.
I appreciate your patience! Definitely doesn’t go unnoticed with me.
Buddy, you are absolutely nailing what I have been experiencing and what’s going through my mind.
I started on the css/html stuff around April, and moved onto the JS, then bounced to a Udemy JS course, now I’m back to FCC… But I get side tracked by little things I don’t understand (like the npm), and spend weeks trying to figure it out. And sometimes, as it turns out, the information is beyond my knowledge base so I can’t even get a great grasp of it anyway because I’m missing other information to link it all together.
But yes, when I don’t understand something my mind wants to get to the bottom of it and figure out it’s fundamentals… But it’s causing me to be horribly slow with getting through FCC… So I’m going to have to start just moving forward, do what I can to finish the lessons/projects, and trust the process that it’ll all eventually come together.