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

334
Visualizações
cannot import npm installed modules (lightweight-charts)

I'm new to the world of JS and recently trying to write a toy app using lightweight-charts. I've gone through several tutorials and learned some basic concepts. But I'm so mad at myself that I still cannot figure out in what context can I use the 'es6 via npm' example mentioned in the lightweight-chart NPM page above. The CDN example seems to be fine, though.

Here is what I did

  1. install lightweight-charts locally. - npm install lightweight-charts

  2. create a test.mjs in the same directory, which contains only one lines.

import { createChart } from 'lightweight-charts';
  1. run the code. node test.mjs

But I got the following errors

SyntaxError: Named export 'createChart' not found. The requested module 'lightweight-charts' is a CommonJS module, which may not support all module.exports as named exports.

It does not make sense for me because the official npm site says es6 supported, but the error messages seem to indicate that this module is for CommonJS. Even after I
rewrote this in CommonJS style using 'require' syntax and rename "test.mjs" to "test.js", some dependency modules are still using 'import' syntax and caused some so
rt of "cannot use import statement outside a module" errors.

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

This package is not meant to be executed on the backend with NodeJS. It will only work in the browser.

about 4 years ago · Santiago Trujillo Relatório

0

Maybe you need to install Babel compiler here

about 4 years ago · Santiago Trujillo 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