Code Monkey home page Code Monkey logo

Comments (4)

jjmountain avatar jjmountain commented on May 30, 2024

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.

0x80 avatar 0x80 commented on May 30, 2024

@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.

0x80 avatar 0x80 commented on May 30, 2024

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.

0x80 avatar 0x80 commented on May 30, 2024

Closing this because, as I mentioned, the issue is not the responsibility of isolate-package

from isolate-package.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.