You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Requests that fall through here cannot be matched by any other externals config ahead.
1031
-
// Treat all these requests as relative import of source code. Node.js won't add the
1032
-
// leading './' to the relative path resolved by `path.relative`. So add manually it here.
1033
-
if(resolvedRequest[0]!=='.'){
1034
-
resolvedRequest=`./${resolvedRequest}`;
1031
+
1032
+
// only handle the request that is not in node_modules
1033
+
if(!resolvedRequest.includes('node_modules')){
1034
+
resolvedRequest=normalizeSlash(
1035
+
path.relative(
1036
+
path.dirname(contextInfo.issuer),
1037
+
resolvedRequest,
1038
+
),
1039
+
);
1040
+
// Requests that fall through here cannot be matched by any other externals config ahead.
1041
+
// Treat all these requests as relative import of source code. Node.js won't add the
1042
+
// leading './' to the relative path resolved by `path.relative`. So add manually it here.
1043
+
if(resolvedRequest[0]!=='.'){
1044
+
resolvedRequest=`./${resolvedRequest}`;
1045
+
}
1046
+
}else{
1047
+
// NOTE: If request is a phantom dependency, which means it can be resolved but not specified in dependencies or peerDependencies in package.json, the output will be incorrect to use when the package is published
1048
+
// return the original request instead of the resolved request
1049
+
returncallback(undefined,request);
1035
1050
}
1036
1051
}catch(e){
1052
+
// catch error when request can not be resolved by resolver
1037
1053
// e.g. A react component library importing and using 'react' but while not defining
1038
1054
// it in devDependencies and peerDependencies. Preserve 'react' as-is if so.
1039
-
logger.warn(
1055
+
logger.debug(
1040
1056
`Failed to resolve module ${color.green(`"${resolvedRequest}"`)} from ${color.green(contextInfo.issuer)}. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.`,
1041
1057
);
1042
1058
}
@@ -1271,6 +1287,7 @@ async function composeLibRsbuildConfig(
"warn Failed to resolve module "./bar.js" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.",
21
-
"warn Failed to resolve module "./foo" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.",
22
-
"warn Failed to resolve module "lodash" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.",
23
-
]
24
-
`,
25
-
);
26
-
27
10
const{content: indexContent}=queryContent(
28
11
contents.esm0!,
29
12
/esm\/index\.js/,
30
13
);
31
14
32
15
expect(indexContent).toMatchInlineSnapshot(`
33
16
"import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
17
+
import * as __WEBPACK_EXTERNAL_MODULE_prettier__ from "prettier";
34
18
import * as __WEBPACK_EXTERNAL_MODULE__bar_js__ from "./bar.js";
35
19
import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "./foo.js";
"warn Failed to resolve module "./bar.js" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.",
84
-
"warn Failed to resolve module "./foo" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.",
85
-
"warn Failed to resolve module "lodash" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.",
86
-
]
87
-
`,
88
-
);
89
-
90
54
const{content: indexContent}=queryContent(
91
55
contents.esm2!,
92
56
/esm\/index\.js/,
93
57
);
94
58
95
59
expect(indexContent).toMatchInlineSnapshot(`
96
60
"import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
61
+
import * as __WEBPACK_EXTERNAL_MODULE_prettier__ from "prettier";
97
62
import * as __WEBPACK_EXTERNAL_MODULE__bar_js__ from "./bar.js";
98
63
import * as __WEBPACK_EXTERNAL_MODULE__foo__ from "./foo";
Copy file name to clipboardExpand all lines: website/docs/en/config/lib/auto-external.mdx
+6
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,12 @@ overviewHeaders: [2, 3]
4
4
5
5
# lib.autoExternal
6
6
7
+
:::info
8
+
9
+
`autoExternal` is a specific configuration for bundle mode. It will not take effect in bundleless mode (set [lib.bundle](/config/lib/bundle) to `false`) since deps will not be bundled in bundleless mode.
Copy file name to clipboardExpand all lines: website/docs/en/config/lib/redirect.mdx
+1-1
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ overviewHeaders: [2, 3]
6
6
7
7
:::info
8
8
9
-
Redirect is the unique configuration for bundleless mode (set [lib.bundle](/config/lib/bundle) to `false`). It will not take effect in bundle mode where all output files are packaged into a single file, eliminating the need for import path redirection.
9
+
`redirect` is the unique configuration for bundleless mode (set [lib.bundle](/config/lib/bundle) to `false`). It will not take effect in bundle mode where all output files are packaged into a single file, eliminating the need for import path redirection.
10
10
11
11
As bundleless mode is still under development, additional redirect configurations will be introduced in the future.
Copy file name to clipboardExpand all lines: website/docs/en/guide/advanced/third-party-deps.mdx
+2
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# Handle Third-Party Dependencies
2
2
3
+
This section introduces how to handle third-party dependencies in bundle mode.
4
+
3
5
Generally, third-party dependencies required by a project can be installed via the `install` command in the package manager. After the third-party dependencies are successfully installed, they will generally appear under `dependencies` and `devDependencies` in the project `package.json`.
0 commit comments