nx build produce only types, not executable .js code
See original GitHub issueI want to use nx
as a place, that contain publishable react-native libraries, which I can easily develop and distribute.
For achieve this, I do all steps describes in tutorial page
Steps to Reproduce
- Create workspace without nx cloud
npx create-nx-workspace your-workspace-name \
--preset=react-native \
--appName=your-app-name
-
cd your-workspace-name
-
Generate publishable react-native library
npx nx g @nrwl/react-native:lib your-lib-name --publishable --importPath @whalemare/your-lib-name
-
Add some stub files with logic (interface Logger, and implementation ConsoleLogger)
-
Prepare lib for publishing, by calling
npx nx build your-lib-name
-
Try to execute bundled code with
node index.umd.js
Current Behavior
NX build with success only entry point of library without any implementation details
I was try to dig deeper, and found that build is done with rollup
. But I don’t know why it emit only typings, without implementation details.
Bundling your-lib-name...
index.esm.js 57 Bytes
index.umd.js 195 Bytes
⚡ Done in 1.18s

When I execute bundled code with node index.umd.js
I receive ‘MODULE_NOT_FOUND’ error
node index.umd.js
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module './logger'
Require stack:
- /Users/whalemare/dev/temp/your-workspace-name/dist/libs/your-lib-name/index.umd.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at /Users/whalemare/dev/temp/your-workspace-name/dist/libs/your-lib-name/index.umd.js:6:186
at /Users/whalemare/dev/temp/your-workspace-name/dist/libs/your-lib-name/index.umd.js:3:2
at Object.<anonymous> (/Users/whalemare/dev/temp/your-workspace-name/dist/libs/your-lib-name/index.umd.js:4:3)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/whalemare/dev/temp/your-workspace-name/dist/libs/your-lib-name/index.umd.js'
]
}
Expected Behavior
NX build entry points and implementations files, how it do tsc
compiler.
dist/libs/your-lib-name
folder contains as index.js file and ConsoleLogger.js

Repository with reproducible example: https://github.com/whalemare/nx-reproduce-not-found-module.git
Environment
> NX Report complete - copy this into the issue template
Node : 16.13.1
OS : darwin arm64
npm : 8.1.2
nx : 13.8.5
@nrwl/angular : undefined
@nrwl/cli : 13.8.5
@nrwl/cypress : 13.8.5
@nrwl/detox : 13.8.5
@nrwl/devkit : 13.8.5
@nrwl/eslint-plugin-nx : 13.8.5
@nrwl/express : undefined
@nrwl/jest : 13.8.5
@nrwl/js : 13.8.5
@nrwl/linter : 13.8.5
@nrwl/nest : undefined
@nrwl/next : undefined
@nrwl/node : undefined
@nrwl/nx-cloud : undefined
@nrwl/react : 13.8.5
@nrwl/react-native : 13.8.5
@nrwl/schematics : undefined
@nrwl/storybook : 13.8.5
@nrwl/tao : 13.8.5
@nrwl/web : 13.8.5
@nrwl/workspace : 13.8.5
typescript : 4.5.5
rxjs : 6.6.7
---------------------------------------
Community plugins:
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
to build the react native library, there are a few steps:
2 in your lib’s tsconfig.lib.json, add below to compilerOptions:
I managed to get the (compiled) source-code in the dist/index.js by exporting the js-files in the original index.js using “export * from ./mycomponent” etc.
it’s right though, that the components itself are only visible as type-definition (e.g. mycomponent.d.ts) and it’s (compiled) code is all in the index.js, right?