找不到模块:错误:无法解析“fs、net、path、util、os ...”

Lee*_*Hee 5 node.js express webpack apollo-server webpack-5

使用webpack打包时出现以下错误。

我按照错误描述的方法设置了,但是不知道问题出在哪里。

  • Express / apollo 服务器 / 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 inc