与 webpack 捆绑时出现以下错误。
我是按照错误描述的方法设置的,但是不知道是哪里出了问题。
- 快递/阿波罗服务器/ webpack5
错误
共 42 个重复错误。
ERROR in ./node_modules/apollo-env/lib/utils/createHash.js 6:15-39
Module not found: Error: Can't resolve 'crypto' in '/Users/pj/v2/server/node_modules/apollo-env/lib/utils'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
@ ./node_modules/apollo-env/lib/utils/index.js 6:9-32
@ ./node_modules/apollo-env/lib/index.js 8:9-27
@ ./node_modules/@apollographql/apollo-tools/lib/index.js 6:0-21
@ ./node_modules/apollo-server-core/dist/ApolloServer.js 41:23-61
@ ./node_modules/apollo-server-core/dist/index.js 37:21-46
@ ./node_modules/apollo-server-express/dist/index.js 13:27-56
@ ./src/index.js 2:0-53 57:19-31
ERROR in ./node_modules/apollo-server-core/dist/ApolloServer.js 28:14-28
Module not found: Error: Can't resolve 'net' in '/Users/pj/v2/server/node_modules/apollo-server-core/dist'
@ ./node_modules/apollo-server-core/dist/index.js 37:21-46
@ ./node_modules/apollo-server-express/dist/index.js 13:27-56
@ ./src/index.js 2:0-53 57:19-31
ERROR in ./node_modules/apollo-server-core/dist/ApolloServer.js 29:14-28
Module not found: Error: Can't resolve 'tls' in '/Users/pj/v2/server/node_modules/apollo-server-core/dist'
@ ./node_modules/apollo-server-core/dist/index.js 37:21-46
@ ./node_modules/apollo-server-express/dist/index.js 13:27-56
@ ./src/index.js 2:0-53 57:19-31
ERROR in ./node_modules/apollo-server-core/dist/plugin/schemaReporting/index.js 16:29-42
Module not found: Error: Can't resolve 'os' in '/Users/pj/v2/server/node_modules/apollo-server-core/dist/plugin/schemaReporting'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
- install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "os": false }
@ ./node_modules/apollo-server-core/dist/plugin/index.js 17:11-73
@ ./node_modules/apollo-server-core/dist/index.js 49:13-32
@ ./node_modules/apollo-server-express/dist/index.js 13:27-56
@ ./src/index.js 2:0-53 57:19-31
ERROR in ./node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js 17:15-30
Module not found: Error: Can't resolve 'zlib' in '/Users/pj/v2/server/node_modules/apollo-server-core/dist/plugin/usageReporting'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "zlib": require.resolve("browserify-zlib") }'
- install 'browserify-zlib'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "zlib": false }
@ ./node_modules/apollo-server-core/dist/plugin/usageReporting/index.js 3:15-34
@ ./node_modules/apollo-server-core/dist/plugin/index.js 5:11-71 9:11-79 13:11-88
@ ./node_modules/apollo-server-core/dist/index.js 49:13-32
@ ./node_modules/apollo-server-express/dist/index.js 13:27-56
@ ./src/index.js 2:0-53 57:19-31
ERROR in ./node_modules/apollo-server-core/dist/utils/createSHA.js 9:15-39
Module not found: Error: Can't resolve 'crypto' in '/Users/pj/v2/server/node_modules/apollo-server-core/dist/utils'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
@ ./node_modules/apollo-server-core/dist/determineApolloConfig.js 7:36-64
@ ./node_modules/apollo-server-core/dist/ApolloServer.js 46:32-66
@ ./node_modules/apollo-server-core/dist/index.js 37:21-46
@ ./node_modules/apollo-server-express/dist/index.js 13:27-56
@ ./src/index.js 2:0-53 57:19-31
ERROR in ./node_modules/busboy/lib/main.js 1:9-22
Module not found: Error: Can't resolve 'fs' in '/Users/pj/v2/server/node_modules/busboy/lib'
@ ./node_modules/graphql-upload/lib/processRequest.js 8:37-54
@ ./node_modules/graphql-upload/lib/index.js 10:22-49
@ ./node_modules/apollo-server-core/dist/index.js 47:6-45
@ ./node_modules/apollo-server-express/dist/index.js 13:27-56
@ ./src/index.js 2:0-53 57:19-31
ERROR in ./node_modules/busboy/lib/types/multipart.js 8:21-47
Module not found: Error: Can't resolve 'stream' in '/Users/pj/v2/server/node_modules/busboy/lib/types'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
@ ./node_modules/busboy/lib/main.js 84:2-30
@ ./node_modules/graphql-upload/lib/processRequest.js 8:37-54
@ ./node_modules/graphql-upload/lib/index.js 10:22-49
@ ./node_modules/apollo-server-core/dist/index.js 47:6-45
@ ./node_modules/apollo-server-express/dist/index.js 13:27-56
@ ./src/index.js 2:0-53 57:19-31
ERROR in ./node_modules/content-disposition/index.js 22:15-39
Module not found: Error: Can't resolve 'path' in '/Users/pj/v2/server/node_modules/content-disposition'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
@ ./node_modules/express/lib/response.js 16:25-55
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/cookie-signature/index.js 5:13-30
Module not found: Error: Can't resolve 'crypto' in '/Users/pj/v2/server/node_modules/cookie-signature'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
@ ./node_modules/express/lib/response.js 26:11-43
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/destroy/index.js 14:17-41
Module not found: Error: Can't resolve 'fs' in '/Users/pj/v2/server/node_modules/destroy'
@ ./node_modules/send/index.js 18:14-32
@ ./node_modules/express/lib/response.js 31:11-26
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/destroy/index.js 15:13-30
Module not found: Error: Can't resolve 'stream' in '/Users/pj/v2/server/node_modules/destroy'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
@ ./node_modules/send/index.js 18:14-32
@ ./node_modules/express/lib/response.js 31:11-26
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/dicer/lib/Dicer.js 1:21-47
Module not found: Error: Can't resolve 'stream' in '/Users/pj/v2/server/node_modules/dicer/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
@ ./node_modules/busboy/lib/types/multipart.js 11:12-28
@ ./node_modules/busboy/lib/main.js 84:2-30
@ ./node_modules/graphql-upload/lib/processRequest.js 8:37-54
@ ./node_modules/graphql-upload/lib/index.js 10:22-49
@ ./node_modules/apollo-server-core/dist/index.js 47:6-45
@ ./node_modules/apollo-server-express/dist/index.js 13:27-56
@ ./src/index.js 2:0-53 57:19-31
ERROR in ./node_modules/dicer/lib/PartStream.js 2:21-47
Module not found: Error: Can't resolve 'stream' in '/Users/pj/v2/server/node_modules/dicer/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
@ ./node_modules/dicer/lib/Dicer.js 6:17-40
@ ./node_modules/busboy/lib/types/multipart.js 11:12-28
@ ./node_modules/busboy/lib/main.js 84:2-30
@ ./node_modules/graphql-upload/lib/processRequest.js 8:37-54
@ ./node_modules/graphql-upload/lib/index.js 10:22-49
@ ./node_modules/apollo-server-core/dist/index.js 47:6-45
@ ./node_modules/apollo-server-express/dist/index.js 13:27-56
@ ./src/index.js 2:0-53 57:19-31
ERROR in ./node_modules/dotenv/lib/main.js 24:11-24
Module not found: Error: Can't resolve 'fs' in '/Users/pj/v2/server/node_modules/dotenv/lib'
@ ./src/index.js 4:0-28 15:0-13
ERROR in ./node_modules/dotenv/lib/main.js 25:13-28
Module not found: Error: Can't resolve 'path' in '/Users/pj/v2/server/node_modules/dotenv/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
@ ./src/index.js 4:0-28 15:0-13
ERROR in ./node_modules/etag/index.js 21:13-30
Module not found: Error: Can't resolve 'crypto' in '/Users/pj/v2/server/node_modules/etag'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
@ ./node_modules/express/lib/utils.js 21:11-26
@ ./node_modules/express/lib/application.js 24:18-48 25:25-62 26:19-50
@ ./node_modules/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/etag/index.js 22:12-31
Module not found: Error: Can't resolve 'fs' in '/Users/pj/v2/server/node_modules/etag'
@ ./node_modules/express/lib/utils.js 21:11-26
@ ./node_modules/express/lib/application.js 24:18-48 25:25-62 26:19-50
@ ./node_modules/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/express/lib/application.js 23:11-26
Module not found: Error: Can't resolve 'http' in '/Users/pj/v2/server/node_modules/express/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
- install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "http": false }
@ ./node_modules/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/express/lib/application.js 30:14-37
Module not found: Error: Can't resolve 'path' in '/Users/pj/v2/server/node_modules/express/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
@ ./node_modules/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/express/lib/request.js 18:11-30
Module not found: Error: Can't resolve 'net' in '/Users/pj/v2/server/node_modules/express/lib'
@ ./node_modules/express/lib/express.js 21:10-30
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/express/lib/request.js 20:11-26
Module not found: Error: Can't resolve 'http' in '/Users/pj/v2/server/node_modules/express/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
- install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "http": false }
@ ./node_modules/express/lib/express.js 21:10-30
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/express/lib/response.js 23:11-26
Module not found: Error: Can't resolve 'path' in '/Users/pj/v2/server/node_modules/express/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/express/lib/view.js 17:11-26
Module not found: Error: Can't resolve 'path' in '/Users/pj/v2/server/node_modules/express/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
@ ./node_modules/express/lib/application.js 22:11-28
@ ./node_modules/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/express/lib/view.js 18:9-22
Module not found: Error: Can't resolve 'fs' in '/Users/pj/v2/server/node_modules/express/lib'
@ ./node_modules/express/lib/application.js 22:11-28
@ ./node_modules/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/fs-capacitor/lib/index.js 6:37-54
Module not found: Error: Can't resolve 'crypto' in '/Users/pj/v2/server/node_modules/fs-capacitor/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
@ ./node_modules/graphql-upload/lib/processRequest.js 10:19-42
@ ./node_modules/graphql-upload/lib/index.js 10:22-49
@ ./node_modules/apollo-server-core/dist/index.js 47:6-45
@ ./node_modules/apollo-server-express/dist/index.js 13:27-56
@ ./src/index.js 2:0-53 57:19-31
ERROR in ./node_modules/fs-capacitor/lib/index.js 8:33-46
Module not found: Error: Can't resolve 'fs' in '/Users/pj/v2/server/node_modules/fs-capacitor/lib'
@ ./node_modules/graphql-upload/lib/processRequest.js 10:19-42
@ ./node_modules/graphql-upload/lib/index.js 10:22-49
@ ./node_modules/apollo-server-core/dist/index.js 47:6-45
@ ./node_modules/apollo-server-express/dist/index.js 13:27-56
@ ./src/index.js 2:0-53 57:19-31
ERROR in ./node_modules/fs-capacitor/lib/index.js 10:33-46
Module not found: Error: Can't resolve 'os' in '/Users/pj/v2/server/node_modules/fs-capacitor/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
- install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "os": false }
@ ./node_modules/graphql-upload/lib/processRequest.js 10:19-42
@ ./node_modules/graphql-upload/lib/index.js 10:22-49
@ ./node_modules/apollo-server-core/dist/index.js 47:6-45
@ ./node_modules/apollo-server-express/dist/index.js 13:27-56
@ ./src/index.js 2:0-53 57:19-31
ERROR in ./node_modules/fs-capacitor/lib/index.js 12:35-50
Module not found: Error: Can't resolve 'path' in '/Users/pj/v2/server/node_modules/fs-capacitor/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
@ ./node_modules/graphql-upload/lib/processRequest.js 10:19-42
@ ./node_modules/graphql-upload/lib/index.js 10:22-49
@ ./node_modules/apollo-server-core/dist/index.js 47:6-45
@ ./node_modules/apollo-server-express/dist/index.js 13:27-56
@ ./src/index.js 2:0-53 57:19-31
ERROR in ./node_modules/mime/mime.js 2:9-22
Module not found: Error: Can't resolve 'fs' in '/Users/pj/v2/server/node_modules/mime'
@ ./node_modules/send/index.js 24:11-26
@ ./node_modules/express/lib/response.js 31:11-26
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/send/index.js 23:9-22
Module not found: Error: Can't resolve 'fs' in '/Users/pj/v2/server/node_modules/send'
@ ./node_modules/express/lib/response.js 31:11-26
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/send/index.js 28:11-26
Module not found: Error: Can't resolve 'path' in '/Users/pj/v2/server/node_modules/send'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
@ ./node_modules/express/lib/response.js 31:11-26
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/send/index.js 30:13-30
Module not found: Error: Can't resolve 'stream' in '/Users/pj/v2/server/node_modules/send'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
@ ./node_modules/express/lib/response.js 31:11-26
@ ./node_modules/express/lib/express.js 22:10-31
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./node_modules/serve-static/index.js 19:14-37
Module not found: Error: Can't resolve 'path' in '/Users/pj/v2/server/node_modules/serve-static'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
@ ./node_modules/express/lib/express.js 81:0-40
@ ./node_modules/express/index.js 11:0-41
@ ./src/index.js 1:0-30 11:12-19 47:8-22 54:18-32
ERROR in ./src/index.js 40:17-37
Module not found: Error: Can't resolve 'path' in '/Users/pj/v2/server/src'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
webpack.config.js
完成设置 'node{ooo:"empty"} 和 'resolve fallback'。
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const path = require("path");
module.export = {
entry: "./src/index.js",
mode: "production",
target: "node",
node: {
fs: "empty",
net: "empty",
tls: "empty",
},
resolve: {
modules: ["node_modules"],
extensions: [".js", ".json"],
fallback: {
path: require.resolve("path-browserify"),
util: require.resolve("util/"),
url: require.resolve("url/"),
buffer: require.resolve("buffer/"),
os: require.resolve("os-browserify/browser"),
stream: require.resolve("stream-browserify"),
crypto: require.resolve("crypto-browserify"),
http: require.resolve("stream-http"),
zlib: require.resolve("browserify-zlib"),
},
},
output: {
publicPath: "/",
path: path.resolve(__dirname, "build"),
filename: "index.js",
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
],
},
plugins: [new CleanWebpackPlugin()],
};
包.json
{
...
"scripts": {
"dev:server": "NODE_ENV=development nodemon --exec babel-node ./src/index.js",
"build": "webpack --mode production --progress",
"start:server": "NODE_ENV=production node ./build/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"apollo-server": "^2.19.2",
"apollo-server-express": "^2.19.2",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"compression": "^1.7.4",
"core-js": "^3.8.1",
"cors": "^2.8.5",
"crypto-browserify": "^3.12.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"graphql": "^15.4.0",
"mongoose": "^5.11.7",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"regenerator-runtime": "^0.13.7",
"stream-browserify": "^3.0.0",
"stream-http": "^3.1.1",
"url": "^0.11.0",
"util": "^0.12.3",
"webpack": "^5.16.0",
"webpack-cli": "^4.4.0"
},
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/node": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"babel-loader": "^8.2.2",
"clean-webpack-plugin": "^3.0.0",
"nodemon": "^2.0.6"
}
}