mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix(nuxt): try to resolve node_modules before alias logic (#3505)
Fixes issues with @<organization>/<package> for plugins and more.
This commit is contained in:
parent
78494dac92
commit
842cc19431
@ -181,6 +181,14 @@ module.exports = class Nuxt {
|
||||
}
|
||||
|
||||
resolveAlias(path) {
|
||||
const modulePath = this.resolveModule(path)
|
||||
|
||||
// Try to resolve it as if it were a regular node_module
|
||||
// Package first. Fixes issue with @<org> scoped packages
|
||||
if (modulePath != null) {
|
||||
return modulePath
|
||||
}
|
||||
|
||||
if (path.indexOf('@@') === 0 || path.indexOf('~~') === 0) {
|
||||
return join(this.options.rootDir, path.substr(2))
|
||||
}
|
||||
@ -192,22 +200,31 @@ module.exports = class Nuxt {
|
||||
return resolve(this.options.srcDir, path)
|
||||
}
|
||||
|
||||
resolvePath(path) {
|
||||
// Try to resolve using NPM resolve path first
|
||||
resolveModule(path) {
|
||||
try {
|
||||
const resolvedPath = Module._resolveFilename(path, {
|
||||
paths: this.options.modulesDir
|
||||
})
|
||||
|
||||
return resolvedPath
|
||||
} catch (error) {
|
||||
if (error.code === 'MODULE_NOT_FOUND') {
|
||||
// Continue to try other methods
|
||||
return null
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let _path = this.resolveAlias(path)
|
||||
resolvePath(path) {
|
||||
const modulePath = this.resolveModule(path)
|
||||
|
||||
// Try to resolve path as a node_module package first
|
||||
if (modulePath != null) {
|
||||
return modulePath
|
||||
}
|
||||
|
||||
const _path = this.resolveAlias(path)
|
||||
|
||||
if (existsSync(_path)) {
|
||||
return _path
|
||||
|
Loading…
Reference in New Issue
Block a user