title: Angular 13 package/library throws error "moment is not a function" when imported into a Angular 13 project
body: <p>Im upgrading a private angular library/package (my-lib) so i can migrate all other projects, but when imported into a project one of the services uses moment and throws an error:
  &quot;ERROR TypeError: moment is not a function&quot;</p>
  <p>The library works in dev mode and the build and publish are ok and even when imported into a project all components and resources load fine and no errors are displayed, dependencies are download but seeams that some of the 3rd party dependencies are not known by &quot;my-lib&quot; after imported.</p>
  <p>Even in the project i can import moment and use it but &quot;my-lib&quot; in node_modules dont see that package.</p>
  <p>some of the files in &quot;my-lib&quot;</p>
  <p><strong>service.ts</strong></p>
  <pre><code>import * as moment_ from 'moment';
  
  const moment = moment_;
  ...
  
  moment(value).format('YYYY-MM-DD')  ----&gt; line that throws the error
  </code></pre>
  <p>already tried</p>
  <pre><code>import moment from 'moment';
  </code></pre>
  <p>and the &quot;allowSyntheticDefaultImports&quot; flag in tsconfig</p>
  <p><strong>package.json</strong></p>
  <pre><code>&quot;dependencies&quot;: {
      ...
      &quot;moment&quot;: &quot;~2.29.1&quot;,
      ...
  },
  &quot;devDependencies&quot;: {
      &quot;@angular-builders/custom-webpack&quot;: &quot;~13.0.0&quot;,
      &quot;@angular-devkit/build-angular&quot;: &quot;~13.1.1&quot;,
      &quot;@angular-eslint/builder&quot;: &quot;~13.0.1&quot;,
      &quot;@angular-eslint/eslint-plugin&quot;: &quot;~13.0.1&quot;,
      &quot;@angular-eslint/eslint-plugin-template&quot;: &quot;~13.0.1&quot;,
      &quot;@angular-eslint/schematics&quot;: &quot;~13.0.1&quot;,
      &quot;@angular-eslint/template-parser&quot;: &quot;~13.0.1&quot;,
      &quot;@angular/animations&quot;: &quot;~13.1.0&quot;,
      &quot;@angular/cli&quot;: &quot;~13.1.1&quot;,
      &quot;@angular/common&quot;: &quot;~13.1.0&quot;,
      &quot;@angular/compiler&quot;: &quot;~13.1.0&quot;,
      &quot;@angular/compiler-cli&quot;: &quot;~13.1.0&quot;,
      &quot;@angular/core&quot;: &quot;~13.1.0&quot;,
      &quot;@angular/forms&quot;: &quot;~13.1.0&quot;,
      &quot;@angular/language-service&quot;: &quot;~13.1.0&quot;,
      &quot;@angular/platform-browser&quot;: &quot;~13.1.0&quot;,
      &quot;@angular/platform-browser-dynamic&quot;: &quot;~13.1.0&quot;,
      &quot;@angular/router&quot;: &quot;~13.1.0&quot;,
      &quot;eslint&quot;: &quot;^8.2.0&quot;,
      &quot;ng-packagr&quot;: &quot;~13.1.1&quot;,
      &quot;rxjs&quot;: &quot;~7.4.0&quot;,
      &quot;ts-node&quot;: &quot;~10.4.0&quot;,
      &quot;tslib&quot;: &quot;^2.3.0&quot;,
      &quot;typescript&quot;: &quot;~4.5.2&quot;,
      &quot;zone.js&quot;: &quot;~0.11.4&quot;
    }
  </code></pre>
  <p><strong>tsconfig.ts</strong></p>
  <pre><code>{
    &quot;compileOnSave&quot;: false,
    &quot;compilerOptions&quot;: {
      &quot;baseUrl&quot;: &quot;./&quot;,
      &quot;outDir&quot;: &quot;./dist/out-tsc&quot;,
      &quot;forceConsistentCasingInFileNames&quot;: true,
      &quot;strict&quot;: true,
      &quot;noImplicitReturns&quot;: true,
      &quot;strictNullChecks&quot;: false,
      &quot;noImplicitAny&quot;: false,
      &quot;noFallthroughCasesInSwitch&quot;: true,
      &quot;sourceMap&quot;: true,
      &quot;declaration&quot;: false,
      &quot;downlevelIteration&quot;: true,
      &quot;experimentalDecorators&quot;: true,
      &quot;moduleResolution&quot;: &quot;node&quot;,
      &quot;importHelpers&quot;: true,
      &quot;target&quot;: &quot;es2020&quot;,
      &quot;module&quot;: &quot;es2020&quot;,
      &quot;typeRoots&quot;: [
        &quot;node_modules/@types&quot;
      ],
      &quot;types&quot;: [
        &quot;node&quot;,
        &quot;cypress&quot;,
        &quot;cypress-xpath&quot;,
        &quot;cypress-wait-until&quot;
      ],
      &quot;lib&quot;: [
        &quot;es2020&quot;,
        &quot;dom&quot;
      ]
    },
    &quot;angularCompilerOptions&quot;: {
      &quot;compilationMode&quot;: &quot;partial&quot;,
      &quot;enableResourceInlining&quot;: true,
      &quot;enableI18nLegacyMessageIdFormat&quot;: false,
      &quot;strictInjectionParameters&quot;: true,
      &quot;strictInputAccessModifiers&quot;: true,
      &quot;strictTemplates&quot;: true,
      &quot;types&quot;: [
        &quot;node&quot;,
        &quot;cypress&quot;,
        &quot;cypress-xpath&quot;,
        &quot;cypress-wait-until&quot;
      ]
    }
  }
  </code></pre>
  <p><strong>ng-package.json</strong></p>
  <pre><code>{
    &quot;$schema&quot;: &quot;./node_modules/ng-packagr/package.schema.json&quot;,
    &quot;lib&quot;: {
      &quot;entryFile&quot;: &quot;./src/my-lib/public_api.ts&quot;,
      &quot;cssUrl&quot;: &quot;inline&quot;
    },
    &quot;allowedNonPeerDependencies&quot;: [&quot;.&quot;]
  }
  </code></pre>
  <p>this is a update from angular 9 to 13 and probably im missing something but cannot find examples or documentation that explains the change in behavior.</p>
  <p>ps: The &quot;require&quot; function has the same behavior</p>
  <pre><code>const a = require('assets/test.png');   --&gt; throws error require is not a function when my-lib is imported into a project and tries to run the this line
  </code></pre>
  <p>If you need more details or have some suggestions i will apreciate.</p>
  <p>Thanks in advance</p>