Closed j1mmie closed 1 year ago
I may have figured it out. I've set esModuleInterop
to true in my lib's tsconfig. Seems to be working. Going to try a few more things before I close this out.
FWIW, this is what my lib's tsconfig looks like now:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"],
"esModuleInterop": true,
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
AFAIK this is the default that @nrwl/js generates, just with the addition of esModuleInterop
Hi @j1mmie , glad you resolved it.
I've had this issue too in the past with some commonjs npm packages that export an interface rather than a default, and also solved it with esModuleInterop
.
import * as canonicalize from 'canonicalize'
might work also
This is most likely not an issue, and instead a configuration problem or misunderstanding on my end, but any support would be appreciated ❤️
I've created a sample workspace called
nx-workspace-test-apps
(https://github.com/j1mmie/nx-workspace-test-apps), with the following structure:The library,
core
, has some helper methods that utilize the npm packagescanonicalize
andsecp256k1
The intention is that my
game
app and myfunctions
app can both use this helper methods and produce the same output.The
game
app's startup sequence, and the endpointhelloWorld
in thefunctions
app, should both make use ofcore
's helper methods and display similar output.The problem is that the
functions
emulator will not successfully executehelloWorld
, and instead raises an error.When I run
npx nx serve game
, everything works fine. This is the output I see:Those are the expected signatures, but that's irrelevant.
The problem:
When I run the firebase emulators, everything starts up fine. But when I request the
helloWorld
endpoint, I get the following:The
canonicalize
function that mygame
app is using just fine, is not a function in myfunctions
app. I've logged its typeof in thefunctions
app - it is undefinedThis problem is not unique to the
canonicalize
library - it seems to happen with any package thecore
imports. For example, I've tried this with theWebSocketServer
class fromws
- same issue.Additional notes:
When I run
npx nx build functions
, I get this output:That seems great - the two npm dependencies from
@nx-workspace-test-apps/core
are accounted for.Relevant package versions:
Also, I kept a log of everything I did to create this workspace, if that's helpful:
I also removed the e2e folders for this demo repo.
Sorry for the wall of text. Any help with this would be greatly appreciated. Thanks