提前道歉,因为我确信这些都是非常琐碎的事情--我正处于学习前端开发的"hello world“阶段。
我有一个hello-world vite应用程序,我创建并运行它的简单途径是:
npm init @vitejs/app
cd hello-vite
npm install npm run dev我可以在浏览器中查看输出的localhost url。
我还有一个简单的脚本,它导入tensorflow并使用它做一些事情:
$ cat test.mjs
import * as tf from '@tensorflow/tfjs-node'
const a = tf.tensor([[1, 2], [3, 4]]);
a.print();
$ node test.mjs
2022-06-27 22:04:16.968270: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 AVX512F FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Tensor
[[1, 2],
[3, 4]]现在,我想在我的test.mjs应用程序中获得这个hello-vite行为。所以我尝试了这样的方法:
$ cat main.ts
import './style.css'
import * as tf from '@tensorflow/tfjs-node'
const a = tf.tensor([[1, 2], [3, 4]]);
a.print();
document.querySelector('#app').innerHTML = `
<h1>Hello Vite!!!</h1>
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a>
`但是,当我运行npm run dev时,它似乎并不高兴,并且对aws的内容提出了似乎毫无关联的抱怨:
$ npm run dev
> hello-vite@0.0.0 dev
> vite
vite v2.9.12 dev server running at:
> Local: http://localhost:3000/
> Network: use `--host` to expose
ready in 112ms.
✘ [ERROR] Could not resolve "mock-aws-s3"
node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:43:28:
43 │ const AWSMock = require('mock-aws-s3');
╵ ~~~~~~~~~~~~~
You can mark the path "mock-aws-s3" as external to exclude it from the bundle, which will remove
this error. You can also surround this "require" call with a try/catch block to handle this
failure at run-time instead of bundle-time.
✘ [ERROR] Could not resolve "aws-sdk"
node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:76:22:
76 │ const AWS = require('aws-sdk');
╵ ~~~~~~~~~
You can mark the path "aws-sdk" as external to exclude it from the bundle, which will remove this
error. You can also surround this "require" call with a try/catch block to handle this failure at
run-time instead of bundle-time.
✘ [ERROR] Could not resolve "nock"
node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:112:23:
112 │ const nock = require('nock');
╵ ~~~~~~
You can mark the path "nock" as external to exclude it from the bundle, which will remove this
error. You can also surround this "require" call with a try/catch block to handle this failure at
run-time instead of bundle-time.
10:06:42 PM [vite] error while updating dependencies:
Error: Build failed with 3 errors:
node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:43:28: ERROR: Could not resolve "mock-aws-s3"
node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:76:22: ERROR: Could not resolve "aws-sdk"
node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:112:23: ERROR: Could not resolve "nock"
at failureErrorWithLog (/home/dshin/vite_scratch/hello-vite/node_modules/esbuild/lib/main.js:1605:15)
at /home/dshin/vite_scratch/hello-vite/node_modules/esbuild/lib/main.js:1251:28
at runOnEndCallbacks (/home/dshin/vite_scratch/hello-vite/node_modules/esbuild/lib/main.js:1034:63)
at buildResponseToResult (/home/dshin/vite_scratch/hello-vite/node_modules/esbuild/lib/main.js:1249:7)
at /home/dshin/vite_scratch/hello-vite/node_modules/esbuild/lib/main.js:1358:14
at /home/dshin/vite_scratch/hello-vite/node_modules/esbuild/lib/main.js:666:9
at handleIncomingPacket (/home/dshin/vite_scratch/hello-vite/node_modules/esbuild/lib/main.js:763:9)
at Socket.readFromStdout (/home/dshin/vite_scratch/hello-vite/node_modules/esbuild/lib/main.js:632:7)
at Socket.emit (events.js:314:20)
at addChunk (_stream_readable.js:297:12)
Vite Error, /node_modules/.vite/deps/@tensorflow_tfjs-node.js?v=0ea0383e optimized info should be defined如果我注释掉print()调用及其前面的行,错误就会消失。
我做错了什么?我如何理解这些错误?
发布于 2022-06-30 00:11:53
我不知道太多,但@tensorflow/tfjs-节点似乎只是一个节点项目,不会在浏览器中工作。
例如,node-pre-gyp是Node的C++绑定库,在浏览器中绝对不能工作。
您可以尝试执行npm install mock-aws-s3和其他错误的库,看看这对您有多大帮助,但可能没有帮助。
https://stackoverflow.com/questions/72772752
复制相似问题