Comments (2)
For future debugging reference, since sourcemap information is lost for module loading errors, this is one way to debug where the offending reference is being imported from:
function testDirname(): Plugin {
const broken: string[] = [];
return {
name: 'test-dirname',
config(config) {
config.define ??= {};
// Make the build not break
config.define['__dirname'] = 'BROKEN_REFERENCE_FIND_ME';
},
transform(code, id) {
if (!code.includes('BROKEN_REFERENCE_FIND_ME') && !code.includes('__dirname')) return;
console.log('Found broken reference:', id);
broken.push(id);
},
generateBundle() {
for (const id of broken) {
console.log('Broken reference on module:', id);
let importer: string | undefined = id;
while (true) {
const moduleInfo = this.getModuleInfo(importer);
if (!moduleInfo) {
console.log(' Module has no info!');
break;
}
importer = moduleInfo.importers?.[0];
if (!importer) {
break;
}
console.log(' Imported by:', importer);
}
}
}
}
}
In the case of the project references in the issue it shows the following logs:
Broken reference on module: /proj/node_modules/.pnpm/[email protected]/node_modules/source-map/lib/read-wasm.js
Imported by: /proj/node_modules/.pnpm/[email protected]/node_modules/source-map/lib/read-wasm.js?commonjs-proxy
Imported by: /proj/node_modules/.pnpm/[email protected]/node_modules/source-map/lib/source-map-consumer.js
Imported by: /proj/node_modules/.pnpm/[email protected]/node_modules/source-map/lib/source-map-consumer.js?commonjs-proxy
Imported by: /proj/node_modules/.pnpm/[email protected]/node_modules/source-map/source-map.js
Imported by: /proj/node_modules/.pnpm/@[email protected][email protected][email protected]_/node_modules/@astrojs/mdx/dist/plugins.js
Imported by: /proj/node_modules/.pnpm/@[email protected][email protected][email protected]_/node_modules/@astrojs/mdx/dist/vite-plugin-mdx.js
Imported by: /proj/node_modules/.pnpm/@[email protected][email protected][email protected]_/node_modules/@astrojs/mdx/dist/index.js
Imported by: /proj/astro.config.ts
Imported by: /proj/src/pages/[...locale]/[blog]/[...slug].astro
@astrojs/mdx
is being imported at runtime due to the pages importing astro.config.ts
. The integration is a build-time integration, so failing to bundle it in the runtime of an Astro project is expected to break.
from astro.
I've enabled sourcemaps in my astro.config.ts
:
import { defineConfig } from 'astro/config';
import mdx from "@astrojs/mdx";
// https://astro.build/config
export default defineConfig({
vite: {
build: {
sourcemap: true
}
},
prefetch: true,
i18n: {
defaultLocale: "en",
locales: ["de", "en"]
},
integrations: [mdx()]
});
Now the error looks like this:
generating static routes
__dirname is not defined in ES module scope
Stack trace:
at <anonymous> (/workspaces/astro-theme-international/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/native.js:69:23)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:485:26)
at async generatePages (file:///workspaces/astro-theme-international/node_modules/.pnpm/[email protected][email protected]/node_modules/astro/dist/core/build/generate.js:119:7)
at async AstroBuilder.build (file:///workspaces/astro-theme-international/node_modules/.pnpm/[email protected][email protected]/node_modules/astro/dist/core/build/index.js:133:5)
at async build (file:///workspaces/astro-theme-international/node_modules/.pnpm/[email protected][email protected]/node_modules/astro/dist/core/build/index.js:45:3)
ELIFECYCLE Command failed with exit code 1.
```
from astro.
Related Issues (20)
- JSON fields are always escaped when using `sql`
- Query parameters lost and function inconsistently
- Some tests are broken on main branch
- base url not working as expected during dev HOT 3
- Cookies are not persistent when set on a page inside 'account' folder
- Unable to generate RSS feed with directory format consistently across DEV and PROD environments
- Astro is not building to default folder according to docs and running it reports broken module reference. HOT 1
- `hast` element property names converted to `camelCase` when running in MDX mode
- Slow Rendering Performance (Astro is more than 10 times slower than Solid) HOT 1
- Refuse to apply style because its MIME type ('') is not a supported stylesheet MIME type, and strict MIME checking is enabled. HOT 4
- Special characters excluded from content collection slug
- Optimalization: ViewTransition CSS should be after after `<body>` HOT 12
- Rewrite in middleware incorrectly returns a 404 response HOT 1
- Markdown Pages - Links on new tab and additional attribute support HOT 1
- Missing .env variables are incorrectly resolved in SSR mode HOT 1
- Astro Actions: POST Requests with Rewriting Throw 'The Body Has Already Been Consumed' Error
- Minifiy HTML when div in ahref
- Types for `globalThis` aren't recognized
- Nested links being rendered as siblings
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 astro.