import.meta not support in esbuild-loader(target: es2017) evanw/esbuild#349
I hack this issue by moving import.meta.webpackContext to js files, like
// utils/webpack-env
// refs: https://webpack.js.org/api/module-variables/#importmetawebpackcontext
export const contextRequire = import.meta.webpackContext('..', {
recursive: true,
regExp: /.tsx/,
mode: 'sync',
})
then use it in App.tsx
import { contextRequire } from '@/utils/webpack-env'
console.log(contextRequire('./pages/index.tsx'))
or try supports options recommended in evanw/esbuild#349 (comment)
import.metanot support inesbuild-loader(target: es2017)evanw/esbuild#349I hack this issue by moving
import.meta.webpackContexttojsfiles, likethen use it in
App.tsxor try
supportsoptions recommended in evanw/esbuild#349 (comment)