Ivan Vukusic
12/10/2024, 4:49 AMUncaught TypeError: Failed to resolve module specifier "crypto". Relative references must start with either "/", "./", or "../".
I can go into more detail but it seems like this is a ESM/CJS issue.Jason Bosco
12/10/2024, 4:50 AMJason Bosco
12/10/2024, 4:52 AMIvan Vukusic
12/10/2024, 4:53 AMJason Bosco
12/10/2024, 4:53 AMHayden Hoang
12/10/2024, 4:22 PMvite.config.ts
?Ivan Vukusic
12/10/2024, 7:05 PMUncaught TypeError: Failed to resolve module specifier "crypto". Relative references must start with either "/", "./", or "../".
I'll show you the difference with a quick video of the difference running locally and when it gets sent to my staging app.
It has been a second since I touched the vite.config.ts but this is what it should have been liked when Algolia worked.
import { vitePlugin as remix } from '@remix-run/dev'
import { sentryVitePlugin } from '@sentry/vite-plugin'
import { glob } from 'glob'
import { flatRoutes } from 'remix-flat-routes'
import { defineConfig } from 'vite'
import { remixDevTools } from 'remix-development-tools'
import { envOnlyMacros } from 'vite-env-only'
import { cjsInterop } from 'vite-plugin-cjs-interop'
const MODE = process.env.NODE_ENV
export default defineConfig({
//WARN: reason why <https://threads.typesense.org/2Lb60>
// ssr: {
// noExternal: ['typesense-instantsearch-adapter'],
// },
build: {
cssMinify: MODE === 'production',
rollupOptions: {
external: [/node:.*/, 'stream', 'crypto', 'fsevents', 'posthog'],
},
assetsInlineLimit: (source: string) => {
if (
source.endsWith('sprite.svg') ||
source.endsWith('favicon.svg') ||
source.endsWith('apple-touch-icon.png')
) {
return false
}
},
sourcemap: true,
},
server: {
watch: {
ignored: ['**/playwright-report/**'],
},
},
plugins: [
envOnlyMacros(),
remixDevTools(),
cjsInterop({
dependencies: ['typesense-instantsearch-adapter'],
}),
remix({
ignoredRouteFiles: ['**/*'],
serverModuleFormat: 'esm',
routes: async defineRoutes => {
return flatRoutes('routes', defineRoutes, {
ignoredRouteFiles: [
'.*',
'**/*.css',
'**/*.test.{js,jsx,ts,tsx}',
'**/__*.*',
// This is for server-side utilities you want to colocate
// next to your routes without making an additional
// directory. If you need a route that includes "server" or
// "client" in the filename, use the escape brackets like:
// my-route.[server].tsx
'**/*.server.*',
'**/*.client.*',
],
})
},
}),
process.env.SENTRY_AUTH_TOKEN
? sentryVitePlugin({
disable: MODE !== 'production',
authToken: process.env.SENTRY_AUTH_TOKEN,
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
release: {
name: process.env.COMMIT_SHA,
setCommits: {
auto: true,
},
},
sourcemaps: {
filesToDeleteAfterUpload: await glob([
'./build/**/*.map',
'.server-build/**/*.map',
]),
},
})
: null,
],
})
I have tried many iterations to try and make this work. Mainly the steps recommended to try and at the remix link here: https://remix.run/docs/en/main/guides/vite#esm--cjs
When trying to make it work with cjs-interop plugin mentioned it wouldn't even run and I get this error:
11:21:53 PM [vite] Error when evaluating SSR module /node_modules/typesense-instantsearch-adapter/lib/TypesenseInstantsearchAdapter.js:
|- ReferenceError: require is not defined
at eval (/Users/vonkoff/GoodUnionJobs/remix-guj/node_modules/typesense-instantsearch-adapter/lib/TypesenseInstantsearchAdapter.js:5:30)
at instantiateModule (file:///Users/vonkoff/GoodUnionJobs/remix-guj/node_modules/vite/dist/node/chunks/dep-BzOvws4Y.js:52870:11)
11:21:53 PM [vite] Error when evaluating SSR module /app/routes/_marketing+/index.tsx:
|- ReferenceError: require is not defined
at eval (/Users/vonkoff/GoodUnionJobs/remix-guj/node_modules/typesense-instantsearch-adapter/lib/TypesenseInstantsearchAdapter.js:5:30)
at instantiateModule (file:///Users/vonkoff/GoodUnionJobs/remix-guj/node_modules/vite/dist/node/chunks/dep-BzOvws4Y.js:52870:11)
11:21:53 PM [vite] Error when evaluating SSR module virtual:remix/server-build:
|- ReferenceError: require is not defined
at eval (/Users/vonkoff/GoodUnionJobs/remix-guj/node_modules/typesense-instantsearch-adapter/lib/TypesenseInstantsearchAdapter.js:5:30)
at instantiateModule (file:///Users/vonkoff/GoodUnionJobs/remix-guj/node_modules/vite/dist/node/chunks/dep-BzOvws4Y.js:52870:11)
ReferenceError: require is not defined
ReferenceError: require is not defined
at eval (/Users/vonkoff/GoodUnionJobs/remix-guj/node_modules/typesense-instantsearch-adapter/lib/TypesenseInstantsearchAdapter.js:5:30)
at instantiateModule (file:///Users/vonkoff/GoodUnionJobs/remix-guj/node_modules/vite/dist/node/chunks/dep-BzOvws4Y.js:52870:11)
Ivan Vukusic
12/10/2024, 7:15 PMHayden Hoang
12/11/2024, 4:35 PMThe stack trace isn't anything besides that console error I mentioned before:Maybe it is hidden from the client, have you checked fly io logging? (You should use SSR for this)
Before with ssr the blocks of jobs and data showed up but nothing was responsive or dynamic. I couldn't click on any of the blocks to open it up.Did you get that same crypto module error regardless of whether SSR is used? It could be possible that
crypto
isn't available in production environment, can you try again after removing 'crypto'
from rollupOptions
?Ivan Vukusic
12/12/2024, 12:05 AM'crypto'
from `rollupOptions`` " was the solution.Ivan Vukusic
12/12/2024, 12:05 AMHayden Hoang
12/12/2024, 12:22 PMWould it be of service to fix up the https://github.com/typesense/showcase-guitar-chords-search-remix repo to the newest version of remix and apply these changes?Thanks for asking! I have opened a PR for that here. @Jason Bosco could you merge it?