Skip to content

Commit

Permalink
Ensure module not found error is shown with jsconfig paths (#11889)
Browse files Browse the repository at this point in the history
* Ensure correct module not found error is shown with jsconfig paths

* bump
  • Loading branch information
ijjk committed Apr 15, 2020
1 parent 67e6cae commit 2b116ce
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 9 deletions.
5 changes: 0 additions & 5 deletions packages/next/build/webpack/plugins/jsconfig-paths-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,6 @@ export class JsConfigPathsPlugin implements ResolvePlugin {

return result
}

throw new Error(`
Request "${moduleName}" matched tsconfig.json or jsconfig.json "paths" pattern ${matchedPatternText} but could not be resolved.
Tried paths: ${triedPaths.join(' ')}
`)
}
)
}
Expand Down
37 changes: 35 additions & 2 deletions test/integration/jsconfig-baseurl/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
/* eslint-env jest */
/* global jasmine */
import fs from 'fs-extra'
import { join } from 'path'
import cheerio from 'cheerio'
import { renderViaHTTP, findPort, launchApp, killApp } from 'next-test-utils'
import {
renderViaHTTP,
findPort,
launchApp,
killApp,
waitFor,
} from 'next-test-utils'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2

Expand All @@ -17,15 +24,41 @@ async function get$(path, query) {

describe('TypeScript Features', () => {
describe('default behavior', () => {
let output = ''

beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {})
app = await launchApp(appDir, appPort, {
onStdout(msg) {
output += msg || ''
},
onStderr(msg) {
output += msg || ''
},
})
})
afterAll(() => killApp(app))

it('should render the page', async () => {
const $ = await get$('/hello')
expect($('body').text()).toMatch(/World/)
})

it('should have correct module not found error', async () => {
const basicPage = join(appDir, 'pages/hello.js')
const contents = await fs.readFile(basicPage, 'utf8')

await fs.writeFile(
basicPage,
contents.replace('components/world', 'components/worldd')
)
await renderViaHTTP(appPort, '/hello')

await waitFor(2 * 1000)
await fs.writeFile(basicPage, contents)
expect(output).toContain(
`Module not found: Can't resolve 'components/worldd' in`
)
})
})
})
32 changes: 30 additions & 2 deletions test/integration/jsconfig-paths/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
/* eslint-env jest */
/* global jasmine */
import fs from 'fs-extra'
import { join } from 'path'
import cheerio from 'cheerio'
import { renderViaHTTP, findPort, launchApp, killApp } from 'next-test-utils'
import {
renderViaHTTP,
findPort,
launchApp,
killApp,
waitFor,
} from 'next-test-utils'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2

Expand All @@ -17,9 +24,18 @@ async function get$(path, query) {

describe('TypeScript Features', () => {
describe('default behavior', () => {
let output = ''

beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {})
app = await launchApp(appDir, appPort, {
onStderr(msg) {
output += msg || ''
},
onStdout(msg) {
output += msg || ''
},
})
})
afterAll(() => killApp(app))

Expand All @@ -42,5 +58,17 @@ describe('TypeScript Features', () => {
const $ = await get$('/single-alias')
expect($('body').text()).toMatch(/Hello/)
})

it('should have correct module not found error', async () => {
const basicPage = join(appDir, 'pages/basic-alias.js')
const contents = await fs.readFile(basicPage, 'utf8')

await fs.writeFile(basicPage, contents.replace('@c/world', '@c/worldd'))
await renderViaHTTP(appPort, '/basic-alias')

await waitFor(2 * 1000)
await fs.writeFile(basicPage, contents)
expect(output).toContain(`Module not found: Can't resolve '@c/worldd' in`)
})
})
})

0 comments on commit 2b116ce

Please sign in to comment.