Skip to content

Cannot import modules prefixed with @ #103

@tristan-kelley

Description

@tristan-kelley

Hi all -

Preval is great and fixes performance issues I was experiencing around constantly re-fetching data during a build. However, one minor problem I have is that Preval can't find modules whose imports are prefixed with @. If I convert the imports to absolute paths Preval works great. I assume there is something simple I'm missing. Any help would be appreciated. Thanks.

Error Message

Error: Failed to pre-evaluate "~/sites/rdc-nextjs-wp-poc/functions/wordpress/archives/getAndCacheAllPosts.preval.js". Error: Cannot find module '@/lib/wordpress/connector.js'

Imports from getAndCacheAllPosts.preval.js

import preval from 'next-plugin-preval'
import {initializeWpApollo} from '@/lib/wordpress/connector.js'
import {gql} from '@apollo/client'

I converted the imports to the below and Preval works

import preval from 'next-plugin-preval'
import {initializeWpApollo} from '../../../lib/wordpress/connector.js'
import {gql} from '../../../node_modules/@apollo/client'

next.config.js

const withPlugins = require('next-compose-plugins')
const withPreact = require('next-plugin-preact')
const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true'
})

const createNextPluginPreval = require('next-plugin-preval/config')
const withNextPluginPreval = createNextPluginPreval()

module.exports = withNextPluginPreval(
  withPlugins([
    withBundleAnalyzer,
    {
      productionBrowserSourceMaps: true,
      trailingSlash: true,
      swcMinify: true,
      withPreact
  ])
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions