Closed jasikpark closed 1 year ago
Yeah, right now it's just doing a dumb tsc
compile, not anything fancier.
What tsconfig
module options are you using there?
{
"compilerOptions": {
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"jsx": "preserve",
"noEmit": true,
// Typescript 4.0 allows incremental typechecks: https://devblogs.microsoft.com/typescript/announcing-typescript-4-0-beta/#incremental-with-noemit
"incremental": true,
"baseUrl": ".",
"typeRoots": ["node_modules", "types"], // https://github.com/microsoft/TypeScript/issues/54629#issuecomment-1589593147
"types": ["vite/client", "vite-plugin-svgr/client"],
"strict": true,
"noImplicitOverride": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"noUncheckedIndexedAccess": true,
"verbatimModuleSyntax": true,
"plugins": [{ "name": "typescript-plugin-css-modules" }],
// If you add any more aliases here, be sure to also add it to .prettierc.cjs
"paths": {
"@api/*": ["src/api/*"],
"@api": ["src/api/"],
"@assets/*": ["src/assets/*"],
"@components/*": ["src/components/*"],
"@global/*": ["src/global/*"],
"@hooks/*": ["src/hooks/*"],
"@mock/*": ["mock/*"],
"@screens/*": ["src/screens/*"],
"@test-setup/*": ["test-setup/*"],
"@dn-types/*": ["types/*"],
"@util/*": ["src/util/*"]
}
},
"include": ["src", "types", "test-setup", "mock", "e2e"],
"exclude": ["functions/**/*"]
}
I think this is an indication that something's a bit weird somewhere though?
Yeah, that's my point. Thus far I haven't put any effort into "bundling" the output or trying to improve the package.exports
stuff. It's just straight tsc
compilation output.
hmm, ok, I may try to muck around and sort it out thenn
I think one pertinent problem may be marking the package.json as module syntax w/ type: 'module'
but outputting CommonJS - https://github.com/markerikson/react-prod-sourcemaps/blob/446dd17d335a0f8a69f0af10f89255c7fbfd2b65/tsconfig.json#L8
Since node supports ESM solidly nowadays, maybe we could output ESM instead of CommonJS or outputting both? ex: https://github.com/vitejs/vite/discussions/13928
oh wait, yeah, why do we have type: "module"
? I found that just causes more problems in general - it's better to have the specific filenames instead:
https://blog.isquaredsoftware.com/2023/08/esm-modernization-lessons/
I just fixed this - I removed type:module and used tsup to output ESM and CJS builds in https://github.com/markerikson/react-prod-sourcemaps/pull/10
Updated #10 and it should look good now:
┌───────────────────┬───────────────────────────────────┐
│ │ "@acemarke/react-prod-sourcemaps" │
├───────────────────┼───────────────────────────────────┤
│ node10 │ 🟢 │
├───────────────────┼───────────────────────────────────┤
│ node16 (from CJS) │ 🟢 (CJS) │
├───────────────────┼───────────────────────────────────┤
│ node16 (from ESM) │ 🟢 (ESM) │
├───────────────────┼───────────────────────────────────┤
│ bundler │ 🟢 │
└───────────────────┴───────────────────────────────────┘
Okay, published https://github.com/markerikson/react-prod-sourcemaps/releases/tag/0.1.0 !
thx! i'll test today
I just tested this for Sentry and it properly remapped our react build. @markerikson do you think there is a chance we could generate sourcemaps for react-dom/profiling bundle as well? There seem to be a lot of folks (including us at Sentry) that use this in production.
upgrading to 0.1.0 and i'm nearly there! just hit one more snag:
✓ 2586 modules transformed.
computing gzip size (0)...[react-sourcemaps] __dirname is not defined
✓ built in 7.45s
error during build:
ReferenceError: __dirname is not defined
at loadExistingReactDOMSourcemap (file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/@acemarke+react-prod-sourcemaps@0.1.0/node_modules/@acemarke/react-prod-sourcemaps/lib/index.mjs:195:31)
at file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/@acemarke+react-prod-sourcemaps@0.1.0/node_modules/@acemarke/react-prod-sourcemaps/lib/index.mjs:258:12
at file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/@ampproject+remapping@2.2.1/node_modules/@ampproject/remapping/dist/remapping.mjs:132:27
at Array.map (<anonymous>)
at build (file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/@ampproject+remapping@2.2.1/node_modules/@ampproject/remapping/dist/remapping.mjs:119:38)
at buildSourceMapTree (file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/@ampproject+remapping@2.2.1/node_modules/@ampproject/remapping/dist/remapping.mjs:110:16)
at remapping (file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/@ampproject+remapping@2.2.1/node_modules/@ampproject/remapping/dist/remapping.mjs:186:18)
at maybeRewriteSourcemapWithReactProd (file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/@acemarke+react-prod-sourcemaps@0.1.0/node_modules/@acemarke/react-prod-sourcemaps/lib/index.mjs:233:20)
at rewireSourceMapsFromGeneratedAssetList (file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/@acemarke+react-prod-sourcemaps@0.1.0/node_modules/@acemarke/react-prod-sourcemaps/lib/index.mjs:31:27)
at Object.writeBundle (file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/@acemarke+react-prod-sourcemaps@0.1.0/node_modules/@acemarke/react-prod-sourcemaps/lib/index.mjs:80:11)
at file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/rollup@3.29.3/node_modules/rollup/dist/es/shared/node-entry.js:25539:40
at async Promise.all (index 0)
at async PluginDriver.hookParallel (file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/rollup@3.29.3/node_modules/rollup/dist/es/shared/node-entry.js:25467:9)
at async file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/rollup@3.29.3/node_modules/rollup/dist/es/shared/node-entry.js:26787:13
at async catchUnfinishedHookActions (file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/rollup@3.29.3/node_modules/rollup/dist/es/shared/node-entry.js:25905:16)
at async build (file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/vite@5.0.0-beta.1/node_modules/vite/dist/node/chunks/dep-e31699fa.js:48096:22)
at async CAC.<anonymous> (file:///Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/vite@5.0.0-beta.1/node_modules/vite/dist/node/cli.js:842:9)
ELIFECYCLE Command failed with exit code 1.
maybe it's b/c i have
build: {
outDir: '.definednet/build',
// Generate source maps for sentry, but don't expose them to the public
sourcemap: mode === 'production' ? 'hidden' : true,
},
set in my Vite config?
where does __dirname
come from? all I see is
and
Yeah, __dirname
implicitly exists in CJS modules, but not ESM. But import.meta
exists in ESM and not CJS.
I have a tentative fix for that in #12 .
what's the sourcemap viz tool that you use?
__dirname
issue should be fixed:
https://github.com/markerikson/react-prod-sourcemaps/releases/tag/v0.2.0
ayyye yup that was my last issue - i just merged a setup using the Vite plugin w/ a pnpm patch for fixing the __dirname
usage
When trying to integrate the Vite plugin, I get this error:
which matches the errors described in https://arethetypeswrong.github.io/?p=%40acemarke%2Freact-prod-sourcemaps%400.0.5