|
1 |
| -const path = require('path') |
| 1 | +const getNextConfig = require('./getNextConfig') |
2 | 2 |
|
3 |
| -// Checks if site has the correct next.cofig.js |
| 3 | +// Checks if site has the correct next.config.js |
4 | 4 | const hasCorrectNextConfig = async ({ nextConfigPath, failBuild }) => {
|
5 | 5 | // In the plugin's case, no config is valid because we'll make it ourselves
|
6 | 6 | if (nextConfigPath === undefined) return true
|
7 | 7 |
|
8 |
| - // We cannot load `next` at the top-level because we validate whether the |
9 |
| - // site is using `next` inside `onPreBuild`. |
10 |
| - const { PHASE_PRODUCTION_BUILD } = require('next/constants') |
11 |
| - const { default: loadConfig } = require('next/dist/next-server/server/config') |
| 8 | + const { target } = await getNextConfig(failBuild) |
12 | 9 |
|
13 | 10 | // If the next config exists, log warning if target isnt in acceptableTargets
|
14 | 11 | const acceptableTargets = ['serverless', 'experimental-serverless-trace']
|
15 |
| - let nextConfig |
16 |
| - try { |
17 |
| - nextConfig = await loadConfig(PHASE_PRODUCTION_BUILD, path.resolve('.')) |
18 |
| - } catch (error) { |
19 |
| - return failBuild('Error loading your next.config.js.', { error }) |
20 |
| - } |
21 |
| - const isValidTarget = acceptableTargets.includes(nextConfig.target) |
| 12 | + const isValidTarget = acceptableTargets.includes(target) |
22 | 13 | if (!isValidTarget) {
|
23 | 14 | console.log(
|
24 |
| - `Your next.config.js must set the "target" property to one of: ${acceptableTargets.join(', ')}. Update the |
| 15 | + `Your next.config.js must set the "target" property to one of: ${acceptableTargets.join(', ')}. Update the |
25 | 16 | target property to allow this plugin to run.`,
|
26 | 17 | )
|
27 | 18 | }
|
|
0 commit comments