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

647
Views
El paquete/biblioteca de Angular 13 arroja el error "el momento no es una función" cuando se importa a un proyecto de Angular 13

Estoy actualizando una biblioteca/paquete angular privado (my-lib) para poder migrar todos los demás proyectos, pero cuando se importa a un proyecto, uno de los servicios usa el momento y arroja un error: "ERROR TypeError: el momento no es una función"

La biblioteca funciona en modo dev y la compilación y publicación están bien e incluso cuando se importan a un proyecto, todos los componentes y recursos se cargan bien y no se muestran errores, las dependencias se descargan pero parece que algunas de las dependencias de terceros no son conocidas por "my -lib" después de importar.

Incluso en el proyecto puedo importar el momento y usarlo, pero "my-lib" en node_modules no ve ese paquete.

algunos de los archivos en "my-lib"

servicio.ts

 import * as moment_ from 'moment'; const moment = moment_; ... moment(value).format('YYYY-MM-DD') ----> line that throws the error

ya probado

 import moment from 'moment';

y el indicador "allowSyntheticDefaultImports" en tsconfig

paquete.json

 "dependencies": { ... "moment": "~2.29.1", ... }, "devDependencies": { "@angular-builders/custom-webpack": "~13.0.0", "@angular-devkit/build-angular": "~13.1.1", "@angular-eslint/builder": "~13.0.1", "@angular-eslint/eslint-plugin": "~13.0.1", "@angular-eslint/eslint-plugin-template": "~13.0.1", "@angular-eslint/schematics": "~13.0.1", "@angular-eslint/template-parser": "~13.0.1", "@angular/animations": "~13.1.0", "@angular/cli": "~13.1.1", "@angular/common": "~13.1.0", "@angular/compiler": "~13.1.0", "@angular/compiler-cli": "~13.1.0", "@angular/core": "~13.1.0", "@angular/forms": "~13.1.0", "@angular/language-service": "~13.1.0", "@angular/platform-browser": "~13.1.0", "@angular/platform-browser-dynamic": "~13.1.0", "@angular/router": "~13.1.0", "eslint": "^8.2.0", "ng-packagr": "~13.1.1", "rxjs": "~7.4.0", "ts-node": "~10.4.0", "tslib": "^2.3.0", "typescript": "~4.5.2", "zone.js": "~0.11.4" }

tsconfig.ts

 { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "forceConsistentCasingInFileNames": true, "strict": true, "noImplicitReturns": true, "strictNullChecks": false, "noImplicitAny": false, "noFallthroughCasesInSwitch": true, "sourceMap": true, "declaration": false, "downlevelIteration": true, "experimentalDecorators": true, "moduleResolution": "node", "importHelpers": true, "target": "es2020", "module": "es2020", "typeRoots": [ "node_modules/@types" ], "types": [ "node", "cypress", "cypress-xpath", "cypress-wait-until" ], "lib": [ "es2020", "dom" ] }, "angularCompilerOptions": { "compilationMode": "partial", "enableResourceInlining": true, "enableI18nLegacyMessageIdFormat": false, "strictInjectionParameters": true, "strictInputAccessModifiers": true, "strictTemplates": true, "types": [ "node", "cypress", "cypress-xpath", "cypress-wait-until" ] } }

ng-paquete.json

 { "$schema": "./node_modules/ng-packagr/package.schema.json", "lib": { "entryFile": "./src/my-lib/public_api.ts", "cssUrl": "inline" }, "allowedNonPeerDependencies": ["."] }

esta es una actualización de angular 9 a 13 y probablemente me falta algo, pero no puedo encontrar ejemplos o documentación que explique el cambio de comportamiento.

ps: la función "requerir" tiene el mismo comportamiento

 const a = require('assets/test.png'); --> throws error require is not a function when my-lib is imported into a project and tries to run the this line

Si necesita más detalles o tiene alguna sugerencia, se lo agradeceré.

Gracias por adelantado

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Tuve este problema al intentar ejecutar el momento en stackblitz. Establecer "esModuleInterop":true en compilerOptions y usar el import moment from 'moment' lo arregló para mí. Déjame saber si eso funciona.

Habilitar esmoduleInterop también habilita allowSyntheticDefaultImports .

Más información: https://www.typescriptlang.org/tsconfig#esModuleInterop

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!