Skip to content

Commit

Permalink
fix: 🐛 Use crypto module only on server side
Browse files Browse the repository at this point in the history
Closes: #332
  • Loading branch information
dc7290 committed Dec 8, 2022
1 parent 7569362 commit 1a8d2ed
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/image.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import { createHash } from 'crypto'

import Image, { ImageLoader, ImageProps } from 'next/dist/client/image'
import React from 'react'

Expand Down Expand Up @@ -86,7 +84,8 @@ const exportableLoader: ImageLoader = ({ src: _src, width, quality }) => {
const path = require('path') as typeof import('path')

if (src.startsWith('http')) {
json.src = `/${externalOutputDir}/${createHash('sha1')
json.src = `/${externalOutputDir}/${(require('crypto') as typeof import('crypto'))
.createHash('sha1')
.update(
src
.replace(/^https?:\/\//, '')
Expand Down

0 comments on commit 1a8d2ed

Please sign in to comment.