0

I know this is not related to stoplight or webpack directly but something to do with a package called json-schema-faker which fails to build. Here's how to reproduce. A basic js script to initialise the stoplight client and make a request.

import { getHttpOperationsFromSpec } from '@stoplight/prism-cli/dist/operations'
import { createClientFromOperations } from '@stoplight/prism-http/dist/client'

export const main = async () => {
  const operations = await getHttpOperationsFromSpec('./spec.yaml')
  const client = createClientFromOperations(operations, {
    mock: true
  })

  const result = await client.request('/documents', { method: 'get' })
  console.log(result)
}

main()
  .then(() => console.log('done'))
  .catch(console.error)

Save it as prism.js and create a webpack.config.js file with the following content:

const path = require('path')

module.exports = {
  mode: 'development',
  entry: './src/prism.js',
  output: {
    path: path.resolve(__dirname, 'dist')
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.jsx', '.js', '...']
  },
  target: 'node'
}

Build the bundle by running npx webpack build and after build executing the program fails with the following error

$ node dist/main.js 
webpack://my-webpack-project/./node_modules/.pnpm/@stoplight+prism-http@4.10.5/node_modules/@stoplight/prism-http/dist/mocker/generator/JSONSchema.js?:12
jsf.extend('faker', () => faker_1.default);
    ^

TypeError: jsf.extend is not a function
    at eval (webpack://my-webpack-project/./node_modules/.pnpm/@stoplight+prism-http@4.10.5/node_modules/@stoplight/prism-http/dist/mocker/generator/JSONSchema.js?:12:5)
    at ./node_modules/.pnpm/@stoplight+prism-http@4.10.5/node_modules/@stoplight/prism-http/dist/mocker/generator/JSONSchema.js (/Users/dina//webpack-issue/dist/main.js:21321:1)
    at __webpack_require__ (/Users/dina//webpack-issue/dist/main.js:29241:42)
    at eval (webpack://my-webpack-project/./node_modules/.pnpm/@stoplight+prism-http@4.10.5/node_modules/@stoplight/prism-http/dist/mocker/index.js?:19:22)
    at ./node_modules/.pnpm/@stoplight+prism-http@4.10.5/node_modules/@stoplight/prism-http/dist/mocker/index.js (/Users/dina//webpack-issue/dist/main.js:21332:1)
    at __webpack_require__ (/Users/dina//webpack-issue/dist/main.js:29241:42)
    at eval (webpack://my-webpack-project/./node_modules/.pnpm/@stoplight+prism-http@4.10.5/node_modules/@stoplight/prism-http/dist/forwarder/index.js?:14:18)
    at ./node_modules/.pnpm/@stoplight+prism-http@4.10.5/node_modules/@stoplight/prism-http/dist/forwarder/index.js (/Users/dina//webpack-issue/dist/main.js:21255:1)
    at __webpack_require__ (/Users/dina//webpack-issue/dist/main.js:29241:42)
    at eval (webpack://my-webpack-project/./node_modules/.pnpm/@stoplight+prism-http@4.10.5/node_modules/@stoplight/prism-http/dist/index.js?:7:21)

Can anyone suggest a way forward?

dina
  • 937
  • 1
  • 12
  • 29

0 Answers0