Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Cannot import modules prefixed with @ #103

Open
tristan-kelley opened this issue Sep 16, 2022 · 0 comments
Open

Cannot import modules prefixed with @ #103

tristan-kelley opened this issue Sep 16, 2022 · 0 comments

Comments

@tristan-kelley
Copy link

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
  ])
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant