Closed bholtbholt closed 2 years ago
@bholtbholt did you find a solution to this issue? I have the same problem.
@jonoirwinrsa no, I didn't get anywhere with it 😔
hmm, mind pasting your webpack config here? we use this package in our webpack electron application without any special config (i.e., npm install and nothing else).
Yep, here's webpack.config.js
and package.json
//@ts-check
"use strict";
const path = require("path");
//@ts-check
/** @typedef {import('webpack').Configuration} WebpackConfig **/
/** @type WebpackConfig */
const extensionConfig = {
target: "node", // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
mode: "none", // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
// node: {
// // eslint-disable-next-line @typescript-eslint/naming-convention
// __dirname: false,
// },
entry: "./src/extension.ts", // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
output: {
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, "dist"),
filename: "extension.js",
libraryTarget: "commonjs2",
},
externals: {
// "speech-recorder": "system speech-recorder",
vscode: "commonjs vscode", // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
// modules added here also need to be added in the .vscodeignore file
},
resolve: {
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
extensions: [".ts", ".js"],
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
},
],
},
// {
// test: /\.node$/,
// loader: "node-loader",
// },
],
},
devtool: "nosources-source-map",
infrastructureLogging: {
level: "log", // enables logging required for problem matchers
},
};
module.exports = [extensionConfig];
{
"engines": {
"vscode": "^1.63.0"
},
"activationEvents": [
"onCommand:vippets.startRecording"
],
"main": "./dist/extension.js",
"contributes": {
"commands": []
},
"scripts": {
"vscode:prepublish": "npm run package",
"compile": "webpack --stats verbose",
"watch": "webpack --watch",
"package": "webpack --mode production --devtool hidden-source-map",
"compile-tests": "tsc -p . --outDir out",
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "npm run compile-tests && npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js",
"postinstall": "npm run rebuild",
"rebuild": "electron-rebuild -v 11.1.1 -w speech-recorder -f"
},
"devDependencies": {
"@types/glob": "^7.1.4",
"@types/mocha": "^9.0.0",
"@types/node": "14.x",
"@types/vscode": "^1.63.0",
"@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0",
"@vscode/test-electron": "^1.6.2",
"electron-rebuild": "^3.2.5",
"eslint": "^8.1.0",
"glob": "^7.1.7",
"mocha": "^9.1.3",
"prettier": "^2.5.1",
"ts-loader": "^9.2.5",
"typescript": "^4.4.4",
"webpack": "^5.52.1",
"webpack-cli": "^4.8.0"
},
"dependencies": {
"speech-recorder": "^1.4.0"
}
}
thanks! to make sure I’m interpreting this correctly, this is adding speech-recorder as a dependency for a vscode plugin? (haven’t tried that specifically before, so not sure if vscode imposes any constraints)
Yep, that's correct. From what I learned, VSCode uses Electron under the hood, so I thought I would be able to use any Electron package with the right configuration.
VSCode imposes restrictions around audio/video inputs (at least in January 2022), but I was spiking to see if I could use this package to get around them. I couldn't successfully get past the errors above though.
got it, thanks! we can look into what it would take to support a vscode extension specifically. in the meantime, this library should work when building an electron app with webpack, but anyone can feel free to reopen + post their application configuration if not!
👋 I'm having trouble using this library with Webpack.
I'm working on a VSCode Extension (which uses Electron under the hood and builds like a node library). I'm using Webpack to bundle as the docs say. I'm on a 2017 Mac OSX 12.1.
When I compile I get 1 error and 1 warning:
./node_modules/onnxruntime/bin/napi-v3/darwin/x64/onnxruntime_binding.node
Module parse failed: Unexpected character '�'require(__dirname + "/../build/Release/portaudio.node");
I believe both of these errors are a gap with connecting the binaries (.node) to the Webpack build.
So far I've tried:
node-loader
to handle the error. It works (no more errors), but the library isn't correctly included and causes a runtime error.electron-rebuild
:electron-rebuild -v 11.1.1 -w speech-recorder -f
. This rebuilds, but I might be missing a step that connects it to Webpack. ie. is there a missing step that brings it into thedist/
folder?speech-recorder
as an Externals. Bundles correctly with no errors or warnings, but doesn't include the library (maybe obviously).All of these steps have the same runtime error:
Could not find module root given file: "internal/modules/cjs/loader.js". Do you have a
package.jsonfile? .
I have apackage.json
in the repo.Do you have any suggestions? Am I missing something in the setup?
Errors below