Closed matbour closed 6 months ago
Thanks for reporting. I wasn't aware that exports.types
was still needed when types
is already defined in the root. I will change it soon, and if you like you can also submit a PR.
Do you happen to have a link to some documentation where this requirement is described?
I don't see how this would be related to #56, since that is a runtime error. Can you elaborate on that?
--- edit --- Ah I think I understand. You wrote your script to get around the problem of #56 so it's not directly related.
@mathieu-bour what is your setting for "moduleResolution" in Typescript? I'm trying to figure out why you are having trouble with the types, because my applications don't have this problem.
This an ESM-only package so we shouldn't have to specify what exports are meant for "import" I think, and AFAIK the types field in the root should be picked up by Typescript.
But it might have something to do with the mjs
extension, which isn't the default if you use type: module
, but it's a workaround I had to use.
@0x80 my moduleResolution
is Bundler
. fyi I added the full tsconfig in the first issue.
@mathieu-bour Sorry I missed them because they were collapsed. Neat way to format a longer issue though 👌
@mathieu-bour I had to change it to something else because your proposal broke the integration in firebase-tools-with-isolate
. In the latest version I just do exports: "./dist/index.mjs"
. I hope this works for you, and seems to be the correct way for pure ESM packages.
If it doesn't work, please tell me more about how you're executing your script.
@mathieu-bour did you mean to link #55 instead #56? Seems like that's where the confusion came from.
In order to solve problem described in #56, I built a script to handle my isolation process. However, TypeScript refuses to import the
isolate-package
types.Here is the full error:
I am using isolate-package v1.10.1.
The script:
```ts import { execSync } from 'node:child_process'; import { readFile, writeFile } from 'node:fs/promises'; import { isolate } from 'isolate-package'; import { rimraf } from 'rimraf'; import { build as tsup } from 'tsup'; import tsupConfig from '../tsup.config'; const isolateDirName = 'isolate'; await rimraf(['dist', isolateDirName]); await tsup(tsupConfig); await isolate({ isolateDirName, }); // Copy the overrides from the root workspace to the isolate workspace const rootPackageJson = JSON.parse(await readFile('../../package.json', 'utf-8')); const isolatePackageJson = JSON.parse(await readFile('package.json', 'utf-8')); isolatePackageJson.pnpm = { ...isolatePackageJson.pnpm, overrides: rootPackageJson.pnpm.overrides }; await writeFile('isolate/package.json', JSON.stringify(isolatePackageJson, null, 2)); execSync('pnpm install --lockfile-only', { cwd: isolateDirName, stdio: 'inherit' }); execSync('zip -r ../dist/function.zip ./*', { cwd: isolateDirName, stdio: 'inherit' }); await rimraf([isolateDirName]); ```My tsconfig.json:
```json { "extends": "@tsconfig/strictest/tsconfig.json", "compilerOptions": { "outDir": "dist", "strict": true, "allowJs": false, "checkJs": false, "noEmit": true, "allowImportingTsExtensions": true, "forceConsistentCasingInFileNames": true, "verbatimModuleSyntax": true, "esModuleInterop": true, "resolveJsonModule": true, "isolatedModules": true, "allowSyntheticDefaultImports": true, "exactOptionalPropertyTypes": false, "target": "ES2022", "module": "ESNext", "moduleResolution": "Bundler", "paths": { "@/*": ["./src/*"] } }, "include": ["**/*.ts"], "exclude": ["node_modules"] } ```The fix is fairly easy: add explicit types to the
package.json
exports
:Happy to submit a PR.