# Migration API createAsset "ReferenceError: File is not defined"

**URL:** <https://community.prismic.io/t/migration-api-createasset-referenceerror-file-is-not-defined/18362>\
**Category:** Developing with Prismic\
**Created:** [February 4, 2025, 1:12pm UTC](https://community.prismic.io/t/migration-api-createasset-referenceerror-file-is-not-defined/18362 "2025-02-04T13:12:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev52](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/dev52/32/7984_2.png) [@dev52](https://community.prismic.io/u/dev52)\
**Post date:** [February 4, 2025, 1:12pm UTC](https://community.prismic.io/t/migration-api-createasset-referenceerror-file-is-not-defined/18362/1 "2025-02-04T13:12:40Z")

</div>

## Describe your question/issue in detail

Using the "@prismicio/migrate": "^0.0.2", package, I'm unable to create Assets. I'm assuming it's something I'm doing wrong but I feel like I've followed the documentation and tutorials.

### Impacted feature

Migration API unable to create assets.

### What steps have you taken to resolve this issue already?

Tried hardcoding a URL and using the async method detailed here: [Migrating to Prismic — Prismic Docs](https://prismic.io/docs/migration#defining-asset-related-fields).

### Errors

As soon as the function is fired, I get "ReferenceError: File is not defined at WriteClient.fetchForeignAsset".

Using Node v18.18.0.

### Code

```auto
import Posts from './posts.json' assert { type: 'json' };

const writeClient = prismic.createWriteClient(repo, { writeToken: token});
const migration = prismic.createMigration();

const pageDocument = page => {
	if (!page.title) return;

	const featuredImage = page.images.split('|')[0];

	const post = {
		title: page.title,
		uid: page.slug,
		data: {
			heading: page.title,
			description: page.description,			
			image: migration.createAsset(
				new URL(featuredImage),
				featuredImage.split('/').pop(),
				{
					alt: page.image_alt ? page.image_alt.split('|')[0] : '',
				}
			),
		},
		type: 'post',
		lang: 'en-gb',
	};

	migration.createDocument(post, page.title);
};

for (const page of Posts) {
	pageDocument(page);
}

// Execute the prepared migration at the very end of the script
await writeClient.migrate(migration, {
	reporter: event => console.log(event),
});

```

---

<div class="post-metadata">

**Author:** ![angeloashmore](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/angeloashmore/32/2685_2.png) [@angeloashmore](https://community.prismic.io/u/angeloashmore)\
**Post date:** [February 6, 2025, 7:55pm UTC](https://community.prismic.io/t/migration-api-createasset-referenceerror-file-is-not-defined/18362/2 "2025-02-06T19:55:06Z")

</div>

Hi @dev52, the migration APIs support Node.js 20+, which includes `File` and a few other necessary globals, like `Blob` and `FormData`.

Could you upgrade to Node.js 20 or later and let us know if that fixes the issue?

---

<div class="post-metadata">

**Author:** ![dev52](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/dev52/32/7984_2.png) [@dev52](https://community.prismic.io/u/dev52)\
**Post date:** [February 10, 2025, 4:23pm UTC](https://community.prismic.io/t/migration-api-createasset-referenceerror-file-is-not-defined/18362/3 "2025-02-10T16:23:07Z")

</div>

Yeah - this is the solution! Thank you muchly 😃
