question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript library not being transpiled when imported from app project

See original GitHub issue

Originally posted in #10584, as I thought it was the same issue:

Current Behavior

When importing a typescript library (in the same monorepo) from an app project using “executor”: “@nrwl/web:webpack”, an error is thrown:

ERROR in ../repro-lib/src/index.ts
Module build failed (from ../../node_modules/@nrwl/web/src/utils/web-babel-loader.js):
SyntaxError: /home/lusito/Code/typescript/repro/packages/repro-lib/src/index.ts: Support for the experimental syntax 'flow' isn't currently enabled (3:8):

  1 | export class Repro {}
  2 |
> 3 | export type Second = {
    |        ^
  4 |     repro: Repro;
  5 | };
  6 |

Using “executor”: “@nrwl/node:webpack” works perfectly fine, but I need it to work with web:webpack…

Expected Behavior

TypeScript is transpiled correctly and no error is thrown.

Steps to Reproduce

Here is the smallest reproduction I could make: https://github.com/Lusito/nx-import-type-repro

Environment

>  NX   Report complete - copy this into the issue template

   Node : 18.1.0
   OS   : linux x64
   npm  : 8.8.0
   
   nx : 14.3.6
   @nrwl/angular : Not Found
   @nrwl/cypress : 14.3.6
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.3.6
   @nrwl/eslint-plugin-nx : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 14.3.6
   @nrwl/js : 14.3.6
   @nrwl/linter : 14.3.6
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : 14.3.6
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : 14.3.6
   @nrwl/workspace : 14.3.6
   typescript : 4.7.4
   ---------------------------------------
   Community plugins:

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:6
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
marcputscommented, Jul 8, 2022

I found the solution in #3184.

I added "presets": ["@nrwl/web/babel"] to the babel.config.json file in the monorepo root, and the issue has been solved.

2reactions
srn271commented, Jul 27, 2022

When I copy the .babelrc file from the app to the lib, the app will build succesfully.

I added “presets”: [“@nrwl/web/babel”] to the babel.config.json file in the monorepo root, and the issue has been solved.

Nothing worked for me.

Here is my smallest reproduction i could make: https://github.com/srn271/nx-test-workspace

I am encountering this error in a react-native project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I import and use my transpiled Typescript library using ...
I have a TypeScript library that I've created. I need to know how to import and use this library in a browser. First,...
Read more >
TypeScript Library Import Not Working - JavaScript SDK
Hi,. To use the JavaScript SDK in a React application you need to configure webpack to consume the es6 sources, not the pre-transpiled...
Read more >
Why and how to transpile dependencies of your JavaScript ...
Perks and features of ESM​​ Here are a few reasons: The way we are used to using imports/exports will not work natively. Such...
Read more >
TypeScript: Cannot use import statement outside a module
Another common cause of the "Cannot use import statement outside a module" error in TypeScript is trying to run a TypeScript file directly...
Read more >
Transpiling Typescript into double packages (CommonJS + ...
Instead change the require of index.js in …/file.ts to a dynamic import() which is available in all CommonJS modules. This happens because you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found