Comments (4)
I realized that i needed to have "type": "module"
set in my package.json
and these fields in my tsconfig.json
.
"target": "es2017",
"module": "esnext",
"moduleResolution": "node"
However even with this I'm running into the problem that npx isolate
is not transpiling the code from my shared package from typescript into javascript. According to the firebase function docs this is necessary.
Is there a way to make isolate-package
transpile the code from your shared package (my prisma client in this case)?
Deploy output:
functions:deploy: Error: Failed to load function definition from source: Failed to generate manifest from function source: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/jjdevereux/code/reasily-monorepo/packages/db/index.ts
functions:deploy: npm ERR! Lifecycle script `deploy` failed with error:
functions:deploy: npm ERR! Error: command failed
functions:deploy: npm ERR! in workspace: [email protected]
from isolate-package.
@jjmountain isolate-package will not transpile anything for you. If your shared packages need some sort of compile/transpile step, this should be handled before the isolate process is triggered. The isolate in that sense works similarly to an npm publish. It will pick up the "to be released" files according to your package "files" setting. Since those typically point to a dist folder, you can have a build process do something to your source.
So the issues you are experiencing are not the responsibility of isolate-package.
That being said. I have successfully managed to deploy to firebase using ESM modules for both my shared packaes as the firebase functions source. So I don't think it is not true that functions need to be transpiled.
I was planning to make a pure ESM mono-repo example with firebase deployment, but haven't gotten around to it yet. The project I'm referring to is closed-source, but I will try to look up my configs later today. I'm on the road at the moment...
from isolate-package.
Ah sorry I didn't read your text about transpiling correctly. I associate transpiling with js =>js like ESM to commonjs.
TS always needs to be compiled to JS because it is running on Node.js, so that is not specific to Firebase. The problem you're facing is that your code is compiled to ESM (which uses imports).
You could choose to compile to commonjs (using requires), but commonjs doesn't like requiring ESM. The other way around, importing a commonjs module in an esm module, is not a problem. So it's better to deploy your firebase code from ESM IMO.
This is a hairy subject, because there's a lot of settings you can mess up, and I have spent quite a lot of time on this recently. Like I said, it is out of the scope of isolate-package, but this is what I do:
The package that deploys to firebase has this
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"files": [
"dist"
],
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "nodenext",
"outDir": "dist",
"rootDir": "src",
"lib": ["esnext"],
"sourceMap": true,
"types": ["node"],
"baseUrl": ".",
"paths": {
"~/*": ["src/*"]
}
The shared package something like
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"compilerOptions": {
"target": "esnext",
"rootDir": "src",
"lib": ["esnext"],
"baseUrl": ".",
"paths": {
"~/*": ["src/*"]
}
},
Then compile the shared package with tsc so the dist folder contains js code. Or, I use tsup but that makes it more compicated to get go-to-definition to work in your editor, so that's for another story...
Make sure you're running ESM code using node18 on firebase (configured in firebase.json), otherwise I think ESM is not supported without setting a flag.
from isolate-package.
Closing this because, as I mentioned, the issue is not the responsibility of isolate-package
from isolate-package.
Related Issues (20)
- Asking for all dependencies when using node-linker=hoisted HOT 6
- Where pnpm is the package manager for the repo, would it makes sense to use 'pnpm pack' instead of 'npm pack'? HOT 6
- Firebase functions reloading not working HOT 3
- Patched dependencies are breaking GCP deployments using pnpm HOT 9
- Getting a ERR_MODULE_NOT_FOUND during firebase deploy HOT 9
- Do not include scripts for internal dependencies
- Add support for Rush monorepos HOT 17
- Add support for passing CLI arguments HOT 6
- pnpm overrides are breaking gcp deployments HOT 7
- Failing to pack with PNPM HOT 4
- There are types at 'isolate-package/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". HOT 7
- Isolate seem to be not copying the `.env` file HOT 2
- Remove excess packages from the list in pnpm lockfile
- Fix package registry logic for non-rush repositories
- Strip forceNpm option for sake of simplicity
- Reintroduce excludeLockfile
- Add support for pnpm v9 HOT 4
- trouble shooting some problems HOT 3
- Consistently use pnpm pack if suitable
- Adopt packageManager field from root manifest
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from isolate-package.