Open carlosvillu opened 5 years ago
Hey Carlos!
Can you share the actual code with the spawn()
invocation?
Hi, sure,
worker.js:
import {expose} from 'threads/worker'
expose(async username => {
return {response: `Hello ${username.name}`}
})
Webpack.server.config.js
const webpackConfig = {
context: path.resolve(process.cwd(), 'src'),
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
resolve: {
alias: parseAlias(config.alias),
extensions: ['*', '.js', '.jsx', '.json']
},
entry: './server.js',
target: 'node',
output: {
path: path.resolve(process.cwd(), 'build'),
chunkFilename: '[name].[chunkhash:8].js',
filename: '[name].[chunkhash:8].js'
},
optimization: {
nodeEnv: false
},
externals: [webpackNodeExternals()]
plugins: [
new webpack.DefinePlugin({'global.GENTLY': false}),
new ThreadsPlugin()
],
resolveLoader: {
alias: {
'externals-manifest-loader': require.resolve(
'./loaders/ExternalsManifestLoader'
)
}
},
module: {
rules: cleanList([
babelRules,
{
// ignore css/scss require/imports files in the server
test: /\.s?css$/,
use: ['null-loader']
},
when(config['externals-manifest'], () =>
manifestLoaderRules(config['externals-manifest'])
)
])
}
}
Thx,
Thanks for sharing, but you literally sent me everything that could be interesting except the bit that I asked for 🙈😅
Can you share the actual code with the spawn() invocation?
I really need to see the master thread code with the spawn()
call to rule out something's going wrong there 😉
Maybe I don't get it, but I think what you are asking it is in the first comment:
const greeter = await spawn(new Worker('./worker'))
const {response} = await greeter({name: 'Carlos'})
console.log(response)
await Thread.terminate(greeter)
Or do you mean the complete function?
Ahhh, sorry man – my bad!
Was a bit in a hurry when I responded to the first comment and didn't notice the snippet at the bottom...
So, I don't see any particular reason for this error on first glance. Damn webpack config – it's probably one single option set somewhere.
Will take a deeper look into it later.
Don't worry!!
Thx :)
@andywer could you take a look at this issue ?!
Hey @carlosvillu. Sorry, I've been swamped with work!
This is a tricky one. I am not even sure that anything's wrong with the threads-plugin
as there is in fact an integration test in the threads.js
repo testing node-targeted webpack builds using the threads-plugin
.
It could as well be some weird issue with your webpack config, but I cannot spot anything obviously wrong there either.
The only obvious hint seems to be that it tries to resolve the file created by webpack (0.worker.js
) not with the node.js require()
, but with webpack's require()
. This is of course wrong. The question "why?" remains...
It is as if webpack resolves the module path that it already resolved.
The threads-plugin
is a fork of the worker-plugin
. There doesn't seem to be a known issue like this in the upstream repository either... 😕
Hi,
I am getting an error when I try to use the loader in SSR.
Basically the loader is creating a new file from my worker called
0.worker.js
and putting it in the folder where the server code has been compiled.However, when I try to run this code,
I get the error.
Any suggestions ?!
Thx!
Carlos