TypeScript library not being transpiled when imported from app project
See original GitHub issueOriginally 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:
- Created a year ago
- Reactions:6
- Comments:11 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found the solution in #3184.
I added
"presets": ["@nrwl/web/babel"]
to thebabel.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.