mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
fix(core): improve module not found error (#7267)
Co-authored-by: pooya parsa <pooya@pi0.ir>
This commit is contained in:
parent
7d0da3ff5f
commit
3082567200
@ -160,22 +160,26 @@ export default class ModuleContainer {
|
||||
throw error
|
||||
}
|
||||
|
||||
let message = 'Module `{name}` not found.'
|
||||
// Hint only if entrypoint is not found and src is not local alias or path
|
||||
if (error.message.includes(src) && !/^[~.]|^@\//.test(src)) {
|
||||
let message = 'Module `{name}` not found.'
|
||||
|
||||
if (this.options.buildModules.includes(src)) {
|
||||
message += ' Please ensure `{name}` is in `devDependencies` and installed. HINT: During build step, for npm/yarn, `NODE_ENV=production` or `--production` should NOT be used.'.replace('{name}', src)
|
||||
} else if (this.options.modules.includes(src)) {
|
||||
message += ' Please ensure `{name}` is in `dependencies` and installed.'
|
||||
if (this.options.buildModules.includes(src)) {
|
||||
message += ' Please ensure `{name}` is in `devDependencies` and installed. HINT: During build step, for npm/yarn, `NODE_ENV=production` or `--production` should NOT be used.'.replace('{name}', src)
|
||||
} else if (this.options.modules.includes(src)) {
|
||||
message += ' Please ensure `{name}` is in `dependencies` and installed.'
|
||||
}
|
||||
|
||||
message = message.replace(/{name}/g, src)
|
||||
|
||||
consola.warn(message)
|
||||
}
|
||||
|
||||
message = message.replace(/{name}/g, src)
|
||||
|
||||
if (this.options._cli) {
|
||||
throw new Error(message)
|
||||
throw error
|
||||
} else {
|
||||
// TODO: Remove in next major version
|
||||
message += ' Silently ignoring module as programmatic usage detected.'
|
||||
consola.warn(message)
|
||||
consola.warn('Silently ignoring module as programatic usage detected.')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -462,7 +462,7 @@ describe('core: module', () => {
|
||||
})
|
||||
|
||||
requireModule.mockImplementationOnce(() => {
|
||||
const moduleNotFound = new Error()
|
||||
const moduleNotFound = new Error(`Cannot find module 'test-build-module'`)
|
||||
moduleNotFound.code = 'MODULE_NOT_FOUND'
|
||||
throw moduleNotFound
|
||||
})
|
||||
@ -470,6 +470,7 @@ describe('core: module', () => {
|
||||
const result = await module.addModule('test-build-module', true)
|
||||
|
||||
expect(result).toBeUndefined()
|
||||
expect(consola.warn).toBeCalledWith('Module `test-build-module` not found. Please ensure `test-build-module` is in `devDependencies` and installed. HINT: During build step, for npm/yarn, `NODE_ENV=production` or `--production` should NOT be used. Silently ignoring module as programmatic usage detected.')
|
||||
expect(consola.warn).toBeCalledWith('Module `test-build-module` not found. Please ensure `test-build-module` is in `devDependencies` and installed. HINT: During build step, for npm/yarn, `NODE_ENV=production` or `--production` should NOT be used.')
|
||||
expect(consola.warn).toBeCalledWith('Silently ignoring module as programatic usage detected.')
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user