Skip to content
New issue

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

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

Already on GitHub? # to your account

Error: Cannot find module './xhr-sync-worker.js' #119

Closed
aunruh opened this issue Jan 26, 2024 · 7 comments · Fixed by #121
Closed

Error: Cannot find module './xhr-sync-worker.js' #119

aunruh opened this issue Jan 26, 2024 · 7 comments · Fixed by #121

Comments

@aunruh
Copy link

aunruh commented Jan 26, 2024

node:internal/modules/cjs/loader:1048
  const err = new Error(message);
              ^

Error: Cannot find module './xhr-sync-worker.js'
Require stack:
- /Users/arminunruh/Documents/git/eflux-hygraph-migration/node_modules/@graphcms/html-to-slate-ast/dist/chunk-ARIXHL5V.js
- /Users/arminunruh/Documents/git/eflux-hygraph-migration/node_modules/@graphcms/html-to-slate-ast/dist/index.js
- /Users/arminunruh/Documents/git/eflux-hygraph-migration/migration.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
    at Function.resolve (node:internal/modules/helpers:136:19)
    at /Users/arminunruh/Documents/git/eflux-hygraph-migration/node_modules/@graphcms/html-to-slate-ast/dist/api-VUY5N4BO.js:869:12366
    at /Users/arminunruh/Documents/git/eflux-hygraph-migration/node_modules/@graphcms/html-to-slate-ast/dist/chunk-ARIXHL5V.js:3:443
    at /Users/arminunruh/Documents/git/eflux-hygraph-migration/node_modules/@graphcms/html-to-slate-ast/dist/api-VUY5N4BO.js:870:20714
    at /Users/arminunruh/Documents/git/eflux-hygraph-migration/node_modules/@graphcms/html-to-slate-ast/dist/chunk-ARIXHL5V.js:3:443
    at /Users/arminunruh/Documents/git/eflux-hygraph-migration/node_modules/@graphcms/html-to-slate-ast/dist/api-VUY5N4BO.js:876:73493
    at /Users/arminunruh/Documents/git/eflux-hygraph-migration/node_modules/@graphcms/html-to-slate-ast/dist/chunk-ARIXHL5V.js:3:443
    at /Users/arminunruh/Documents/git/eflux-hygraph-migration/node_modules/@graphcms/html-to-slate-ast/dist/api-VUY5N4BO.js:876:81936
    at /Users/arminunruh/Documents/git/eflux-hygraph-migration/node_modules/@graphcms/html-to-slate-ast/dist/chunk-ARIXHL5V.js:3:443 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/arminunruh/Documents/git/eflux-hygraph-migration/node_modules/@graphcms/html-to-slate-ast/dist/chunk-ARIXHL5V.js',
    '/Users/arminunruh/Documents/git/eflux-hygraph-migration/node_modules/@graphcms/html-to-slate-ast/dist/index.js',
    '/Users/arminunruh/Documents/git/eflux-hygraph-migration/migration.js'
  ]
}

Node.js v20.9.0

This is my code below. Just getting the HTML which is in data.text_html works.
The whole migration works fine, only when i use htmlToSlateAST it gives me this error above.

// TODO: https://github.com/hygraph/rich-text/tree/main/packages/html-to-slate-ast
// https://hygraph.com/docs/getting-started/fundamentals/migrating-to-hygraph#content-api

// Import necessary libraries
const { GraphQLClient, gql } = require('graphql-request') // Importing graphql-request library and gql tag
require('dotenv').config() // Importing environment variables from .env file via the dotenv NPM package

// Initialize GraphQL client with endpoint and authorization headers
const client = new GraphQLClient(process.env.HYGRAPH_ENDPOINT, {
	headers: {
		authorization: `Bearer ${process.env.HYGRAPH_TOKEN}`,
	},
})

const { htmlToSlateAST } = require('@graphcms/html-to-slate-ast')

// Function to create a GraphQL mutation based on provided data
// https://hygraph.com/docs/api-reference/content-api/mutations#upsert-entries
async function createMutation(data) {
	const ast = await htmlToSlateAST(data.text_html)
	console.log(JSON.stringify(ast, null, 2))
	// Create the mutation
	// multiline string: https://stackoverflow.com/questions/45955084/passing-multi-line-string-in-a-graphql-mutation
	const mutation = gql`mutation MyMutation {
    upsertAnnouncement(
        where: { hylexid: "${data._id}" }
        upsert: {
            create: { 
                hylexid: "${data._id}"
                title: "${data.title.trim()}"
                service: "${data.service.trim()}"
                text_html: """${data.text_html.trim()}"""
                image: """${JSON.stringify(data.image, null, 2)}"""
                slug: "${data._slug.trim()}"
                date: "${data.date}"
            }
            update: {
                title: "${data.title.trim()}"
                service: "${data.service.trim()}"
                text_html: """${data.text_html.trim()}"""
                image: """${JSON.stringify(data.image, null, 2)}"""
                slug: "${data._slug.trim()}"
                date: "${data.date}"
            }
        }
      ) {
        id
    }
  }`
	return mutation
}

const pages = 1
// what do i need this for?
let idsToUpdate = []

// Asynchronous function to run the migration process
async function run() {
	let i = 0

	let interval = setInterval(() => {
		if (i > pages) {
			clearInterval(interval)
		}
		console.log(`Running page ${i} of ${pages}`)

		fetchData(i)

		i++
	}, 10000)
}

var fetchData = async function (i) {
	let CAT_API_URL = `https://xxxxxxxxxx/v2/announcements?from=${i}&key=${process.env.API_KEY}`

	const { data } = await fetch(CAT_API_URL).then((res) => res.json())

	// Generate an array of GraphQL mutations based on the retrieved data
	const mutations = data.map((item, index) => {
		return createMutation(item)
	})

	// Execute each mutation after a timed delay
	mutations.forEach((item, index) => {
		setTimeout(() => {
			console.log(`Running mutation ${index + 1} of ${mutations.length}`)
			// Make a request to the GraphQL endpoint using the generated mutation
			client.request(item).then((response) => {
				// console.log('ITEM:')
				// console.log(item)
				// console.log('RESPONSE:')
				// console.log(response)
				idsToUpdate.push(response.id)
			}) // Store the retrieved ID for update
		}, (index + 1) * 1000) // Delay each iteration by (index + 1) seconds
	})
}

// Running the migration process
run()
@jpedroschmitz
Copy link
Contributor

Hey! Thanks for opening this issue!

Can you send me the html data you're passing to htmlToSlateAST? I would need the one that throws the error. This way I can try to reproduce and debug.

@aunruh
Copy link
Author

aunruh commented Jan 27, 2024

Sure!

<p>Kunstraum Niederoesterreich presents its annual exhibition program 2024.</p><p><strong>Heartbeats rising </strong><br>Climate anxiety, climate change distress, ecological grief—judging by the findings of climate psychology, the ecological crisis affects our psyche, too. More and more people are complaining of anxiety, elevated stress, feelings of guilt and inadequacy in the face of a looming planetary collapse. Besides climate anxiety, other fears are also raising the pulse of our times: fear of war, fear of pandemics, fear of social decline. The more the world unravels at the seams, the greater the fear; and the greater the fear, the greater the longing for places and constellations that promise stability: heartbeats instead of heartaches.</p><p>Under the title “Heartbeats Rising”, Kunstraum Niederoesterreich dedicates its 2024 program to the dynamics between feelings and crisis. In three exhibitions, an extensive live program, and free art mediation formats, we and our collaborators will dare a glimpse into the intoxicating spheres of desire, illuminate adolescence as a phase that unleashes the transformative powers of imagination, and explore the complex entanglements of language and body.</p><p>For the 18th time, the Kunstraum awards the <strong>H13 Lower Austria Prize for Performance</strong>, the only award for performance art in Austria. Endowed with 5,000 EUR, the prize will be presented on November 22, 2024. You can find more information <strong><a href="https://www.kunstraum.net/en/performance/performanceprize-h13?set_language=en">here</a></strong>.</p><p><em><strong>Bliss, bliss, bliss</strong></em><br>March 15–May 4 / Opening: March 14</p><p>What strategies do bodies forge to keep going, to find temporary solace or arrive at something like emotional resilience? May we locate a critical potential in the escapist strategies that do succeed in activating our senses, that allow us a temporary feeling of suspension, of being out of world? Together with an intersectional group of artists, <em>Bliss, bliss, bliss</em> tackles questions like these and ventures into the ecstatic, the orgasmic, and the transcendental as potencies to unleash much-needed dreams and imaginaries.</p><p>Artists: James Bantone, Laura Gozlan, Leon Höllhumer, P. Staff, Chin Tsao, and others<br>Curator: Frederike Sperling</p><p><em><strong>All the feels!</strong></em><br>June 7–July 27 / Opening: June 6</p><p><em>All the feels!</em> invites us on a trip through the emotional worlds of teenage years. Historically, “the youth” has always been a driving force behind social change. Even today, in times of climate crisis and wars, it is primarily people between 15 and 24 who insist that a different world is possible. The group exhibition focuses on the fragile moments of growing up and investigates their political potential.</p><p>Artists: Oska Gutheil, Hannah Neckel, Maruša Sagadin, Molly Soda, Anna Witt, and others<br>Curator: Nora Mayr</p><p><strong>Alice Slyngstad: ​</strong><em><strong>Flare demure</strong></em><br>September 6–November 9 / Opening: September 5</p><p>A yes is a yes, and no means no. Somebody either “wants more” or not. But what about the language of the body, which tends to be vague and enigmatic? What do the quickened breath, flushed cheeks, the subtle trembling of a body mean? No? Yes? Maybe? In the artist’s first solo exhibition in Austria, Alice Slyngstad illuminates the complex relationship between language and desire. Can we really catch the body’s will with words?</p><p>Curator: Frederike Sperling</p><p><strong>Symposium 2024: Performance besides Itself. Infra- and Parastructures of a Contemporary Liveness</strong><br>December 6–7 </p><p>What is the relationship between performance art and the institution? How does the institutional set conditions for performance and how do performative practices, in turn, transform the working methods and infrastructures of art institutions? The two-day symposium<em> </em>Performance besides Itself. Infra- and Parastructures of a Contemporary Liveness will address questions like these together with performance curators, theorists, and practitioners.</p><p>Curators: Freda Fiala and Frederike Sperling</p>

oh i see, maybe i should use https://www.npmjs.com/package/html-entities to encode the html mmh

edit: ah nevermind, that didn't work either

@pcdevil
Copy link

pcdevil commented Jan 29, 2024

I'm also having the same issue.

Unfortunately the example code also produces the error: to reproduce you can simpy create an empty Node.js project, install the listed dependencies and copy the code with the test paragraph html to run it.

I created a StackBlitz project for easier debug: https://stackblitz.com/edit/stackblitz-starters-r7mqvq?file=index.js
As far as I can tell the error message comes from jsdom so I pinned it to v22 (as seen package.json) but didn't fix the issue.

Unfortunately I'm not sure what is the root cause, but I hope this helps to debug it!

@jpedroschmitz
Copy link
Contributor

Hey folks! I'm investigating the issue. As a quick workaround, can you use version 0.13.3? I tested it here, and it's working. Thanks for your patience.

@pcdevil
Copy link

pcdevil commented Jan 29, 2024

thanks for taking care of it and the workaround in the meantime! 🙇‍♂️

@jpedroschmitz
Copy link
Contributor

I opened #121, which fixes the issue! As soon as it's published, I'll let you know!

@jpedroschmitz jpedroschmitz linked a pull request Jan 30, 2024 that will close this issue
@jpedroschmitz
Copy link
Contributor

The fix was released on 0.14.1! Thanks folks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants