提前道歉,因为我确信这些都是很琐碎的事情——我正处于学习前端开发的"你好世界"阶段.
我有一个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]]
现在我想在我的hello-vite
应用程序中获得这test.mjs
个行为.所以我try 了以下方法:
$ 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()
个调用和它之前的行,错误就会消失.
我做错了什么?我如何理解这些错误?