Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

2.4K
Views
No se puede hacer una importación predeterminada en Angular 9

Cambié tsconfig.json agregando estas propiedades

"esModuleInterop": true, "allowSyntheticDefaultImports": true,

para poder importar un paquete npm import * as ms from "ms";

Pero sigo recibiendo este error.

 This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.

¿Qué me estoy perdiendo?

Actualizar:

Si cambio con import ms from "ms" , entonces funciona bien con el compilador pero no con VSCode linter y el error es

 can only be default-imported using the 'allowSyntheticDefaultImports' flagts(1259) index.d.ts(25, 1): This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.

Como dije, ahora está funcionando, pero VSCode tiene un problema.

over 4 years ago · Santiago Trujillo
5 answers
Answer question

0

El problema es cómo el paquete declaró la exportación, aún puede importar usando la importación predeterminada:

 import ms from "ms";
over 4 years ago · Santiago Trujillo Report

0

Si tiene este error al intentar importar localforage en angular 9, usé esto (Angular 9.1.12, Typescript 3.9.6):

npm instalar forraje local

// tsconfig.json

 { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "downlevelIteration": true, "experimentalDecorators": true, "module": "esnext", "moduleResolution": "node", "importHelpers": true, "target": "es2015", "lib": [ "es2018", "dom" ] }, "angularCompilerOptions": { "fullTemplateTypeCheck": true, "strictInjectionParameters": true, "esModuleInterop": true, <----------------------------add this "allowSyntheticDefaultImports": true <----------------------------and this }, }

// cualquier componente o servicio

 import * as localforage from 'localforage'; constructor() { localforage.setItem('localforage', 'localforage value'); setTimeout(() => { localforage.getItem('localforage').then((e) => { console.log(e); }); }, 5000); setTimeout( async () => { const RES = await localforage.getItem('localforage'); console.log('RES', RES); }, 10000); }
over 4 years ago · Santiago Trujillo Report

0

Tener el mensaje de error

Este módulo se declara con el uso de 'export =', y solo se puede usar con una importación predeterminada cuando se usa el indicador 'allowSyntheticDefaultImports'.

en una regla de importación mecanografiada para un componente Angular:

 import { something } from 'amodule';

en node_modules/@types/amodule/index.d.ts, encontré este código:

 declare module 'amodule' { export = something; }

y lo cambié a:

 declare module 'amodule' { export default something; }

la regla de importación en el componente angular se cambió a:

 import something from 'amodule';

y el mensaje de error desaparece y el módulo importado se puede usar como se esperaba.

over 4 years ago · Santiago Trujillo Report

0

"allowSyntheticDefaultImports": true

Este indicador resolvió el problema, pero debe agregarse a la sección compilerOptions de tsconfig.json

over 4 years ago · Santiago Trujillo Report

0

Puedes hacer algo como esto

 import * as printJS from 'print-js'
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!