Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

479
Visualizações
Imported Node Module - Error: Cannot find module

I am trying to modify this existing npm package without much success. I have wasted several hours troubleshooting would appreciate some guidance.

https://www.npmjs.com/package/dxf

I have forked the package into my Github account. I have then used npm to install the module locally (W10 running latest LTS Node).

npm i https://github.com/mgbolts/dxf

It installs with no errors but when I require it in my app, I get this error:

Error: Cannot find module 'S:\mgbolts\coding\Udemy\Nodejs\projects\plasma\node_modules\dxf\lib\index.js'. 

Please verify that the package.json has a valid "main" entry

Looking in the dxf module folder, there is no lib subdirectory and the index.js file is located in the src subdirectory. I have modified the package.json file in the dxf package folder to reflect this. After this edit, I now get this error:

S:\mgbolts\coding\Udemy\Nodejs\projects\plasma\node_modules\dxf\src\index.js:1
import config from './config'

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (S:\mgbolts\coding\Udemy\Nodejs\projects\plasma\src\index.js:2:13)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)

I have then tried adding adding a new entry ("type": "module") to the package.json file in the module folder. After that I get this error:

S:\mgbolts\coding\Udemy\Nodejs\projects\plasma\src\index.js:2
const dxf = require('dxf')
            ^
Error [ERR_REQUIRE_ESM]: require() of ES Module S:\mgbolts\coding\Udemy\Nodejs\projects\plasma\node_modules\dxf\src\index.js from S:\mgbolts\coding\Udemy\Nodejs\projects\plasma\src\index.js not supported.

My code is very simple to solve this issue, just a simple const dxf = require('dxf').

Here is an extract of the package.json file as with the two edits mentioned above:

  "name": "dxf",
  "version": "4.6.1",
  "description": "DXF parser for node/browser",
  "main": "src/index.js",
  "type": "module",
  "bin": {
    "dxf-to-svg": "src/cli.js"
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The matter has been resolved. I did not realise that you needed to compile the package when installing from github. Not something required when installing from NPM registry.

The module's package.json file has a script to run the compile process script.
npm run prepublishOnly

Took a little while to install the dependencies (browserify, babel, rimraf) but it compiled and now works...

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda