Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"TypeError: Cannot read property 'send' of undefined" when running next export #21

Open
tom-sherman opened this issue Dec 24, 2018 · 1 comment

Comments

@tom-sherman
Copy link

tom-sherman commented Dec 24, 2018

When I run electron . the app works perfectly, however when I run next build renderer && next export renderer (specifically the next export command) I get the following log:

Note: all of my client code lives in /renderer

[00:22:52] Compiling client
[00:22:52] Compiling server
[00:22:52] Compiled server in 792ms
[00:22:55] Compiled client in 4s
> using build directory: D:\klipped\renderer\.next
  copying "static build" directory
> exporting path: /start
> exporting path: /file
TypeError: Cannot read property 'send' of undefined
    at D:\klipped\renderer\.next\server\static\lXCFzg2cjgmkVrnUKjqkQ\pages\file.js:358:39
    at new Promise (<anonymous>)
    at resolveFilePath (D:\klipped\renderer\.next\server\static\lXCFzg2cjgmkVrnUKjqkQ\pages\file.js:357:10)
    at Function._callee$ (D:\klipped\renderer\.next\server\static\lXCFzg2cjgmkVrnUKjqkQ\pages\file.js:307:24)
    at tryCatch (D:\klipped\node_modules\regenerator-runtime\runtime.js:62:40)
    at Generator.invoke [as _invoke] (D:\klipped\node_modules\regenerator-runtime\runtime.js:288:22)
    at Generator.prototype.(anonymous function) [as next] (D:\klipped\node_modules\regenerator-runtime\runtime.js:114:21)
    at asyncGeneratorStep (D:\klipped\renderer\.next\server\static\lXCFzg2cjgmkVrnUKjqkQ\pages\file.js:228:103)
    at _next (D:\klipped\renderer\.next\server\static\lXCFzg2cjgmkVrnUKjqkQ\pages\file.js:230:194)
    at D:\klipped\renderer\.next\server\static\lXCFzg2cjgmkVrnUKjqkQ\pages\file.js:230:364

Export successful

Here's my code:

next.config.js

exports.webpack = config => Object.assign(config, {
  target: 'electron-renderer'
})

exports.exportPathMap = () => ({
  '/start': { page: '/start' },
  '/file': { page: '/file', query: { data: null, name: null } }
})

file.js

import { ipcRenderer } from 'electron'
import { Component } from 'react'
import { FileDraggable } from '../components/file-draggable'
import Error from 'next/error'

export default class File extends Component {
  static async getInitialProps ({ query }) {
    let filePath

    try {
      if (query.name) {
        filePath = await resolveFilePath({ data: query.data, name: query.name })
      } else {
        filePath = await resolveFilePath({ data: query.data })
      }
    } catch (err) {
      console.error(err)
      return { error: 'Failed to save file.' }
    }

    return { filePath, data: query.data, name: query.name }
  }

  render () {
    return this.props.error
      ? <Error statusCode={500} /> // TODO: Custom error component
      : <FileDraggable filePath={this.props.filePath} name={this.props.name} />
  }
}

function resolveFilePath ({ data, name }) {
  return new Promise((resolve, reject) => {
    ipcRenderer.send('data', { data, name })
    ipcRenderer.on('file', (_, filePath) => resolve(filePath))
    ipcRenderer.on('error', err => reject(err))
  })
}
@tom-sherman tom-sherman changed the title Typeerror when running next export "TypeError: Cannot read property 'send' of undefined" when running next export Dec 24, 2018
@apolkingg8
Copy link

I think that's the reason https://stackoverflow.com/questions/45274548/node-js-require-returns-a-string-instead-of-module-object

But not sure how to solve it. @tom-sherman did you resolved it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants