Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'ssr') #1

Open
IrvingArmenta opened this issue Feb 29, 2024 · 1 comment · May be fixed by #2
Open

Cannot read properties of undefined (reading 'ssr') #1

IrvingArmenta opened this issue Feb 29, 2024 · 1 comment · May be fixed by #2

Comments

@IrvingArmenta
Copy link

I am getting an error when running astro build + astro preview and it seems is related to this package.

my astro config file:

import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';
import sitemap from '@astrojs/sitemap';
import biome from 'astro-biome';
import worker from '@astropub/worker';

// https://astro.build/config
export default defineConfig({
  site: 'https://example.com',
  integrations: [mdx(), sitemap(), worker(), biome()],
});

Error message:

16:23:50 [vite] ✓ 3 modules transformed.
16:23:50 [ERROR] [vite] x Build failed in 18ms
[at position 40] Cannot read properties of undefined (reading 'ssr')
file: ///IntroPhotoSection.astro?astro&type=script&index=0&lang.ts
  Stack trace:
    at Object.handler (///node_modules/.pnpm/@astropub+worker@0.1.0/node_modules/@astropub/worker/integration.js:20:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

shortened some paths for privacy

Any other information I might be able to provide:

packages:

  "dependencies": {
    "@astrojs/check": "^0.5.6",
    "@astrojs/mdx": "^2.1.1",
    "@astrojs/rss": "^4.0.5",
    "@astrojs/sitemap": "^3.1.1",
    "@astropub/worker": "^0.1.0",
    "astro": "^4.4.5",
    "astro-biome": "^0.0.6",
    "typescript": "^5.3.3"
  },
  "devDependencies": {
    "@biomejs/biome": "1.5.3",
    "sass": "^1.71.1",
    "sharp": "^0.33.2",
    "typescript-esbuild": "^0.3.10"
  }

platform: Windows 11
node version: v20.10.0

@bayssmekanique
Copy link

bayssmekanique commented Apr 1, 2024

This can be easily corrected by adding a check to the options param in the integration.js file.

// patch for globalThis.Worker
if (options && options.ssr) {								 
 source.appendLeft(0, `import "@astropub/worker/polyfill";`)
}

Even with this error fixed, the plugin doesn't move the worker files to the dist directory, so the files are not available for the client to utilize.

It does appear that Astro will pick up the files required for the Worker and compile them, however, they don't seem to respect the build.assets configuration and will be output to the dist/assets directory regardless of configuration. I'll open an issue with Astro for this bug.


If all you want is to use workers on the client side, you don't need this integration, just add the worker to your code.

const worker = new Worker(
  new URL('../workers/myWorker.ts', import.meta.url)
)

@FakuOrtiz FakuOrtiz linked a pull request Apr 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants