When have this type of error : Uncaught TypeError: Failed to resolve module specifier. Relative references must start with either "/", "./", or "../β.
Usually, it means youβre using backend node modules in a front app (browser).
The NPM package you are using is likely a package made for node.js code. If in your code, you have something similar to import * as moduleAlias from 'module';
line, it is intended for node.js, and will not work by itself in a browser.
To run these kinds of packages in a browser, you will need to basically convert it using a transpiler. The most common one probably being webpack.
Sometimes packages also include a pre-built or minified version in their package specifically for browsers. If this is the case, you might find a file like something.min.js
in the module
directory.
import * as moduleAlias from './node_modules/.../module.js';
If this is not the case, you unfortunately have to go down some crazy shit with js build tools.
I hope you enjoyed reading this, and I'm curious to hear if this tutorial helped you. Please let me know your thoughts below in the comments. Don't forget to subscribe to my newsletter to avoid missing my upcoming blog posts.
You can also find me here LinkedIn β’ Twitter β’ GitHub or Medium