Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

331
Vistas
How to resolve "Failed to resolve module specifier" error in a npm package?

I have a npm package called "mynpmpackage" . I have a file called index.js that has this content:

export default const Sum = (a , b) => {
return a + b
}

package.json :

{
"name":"mynpmpackage",
"version":"1.0.0",
  "main": "index.js",
  "module": "index.js"
}

I published this package with npm publish and It published correctly . I created another directory , and Installed my package with npm install .

Then , I made an index.html file :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

</body>
<script type="module" src="test.js"></script>
</html>

in test.js :

import Sum from "mynpmpackage"
alert(Sum(3,4))

but it gave this Error :

Uncaught TypeError: Failed to resolve module specifier "mynpmpackage". Relative references must start with either "/", "./", or "../".
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Just replace your package name with ./node_modules/mynpmpackage/index.js

It really works!

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda