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

Cannot read properties of null (reading 'program') #12

Open
rtrembecky opened this issue Dec 13, 2024 · 1 comment
Open

Cannot read properties of null (reading 'program') #12

rtrembecky opened this issue Dec 13, 2024 · 1 comment

Comments

@rtrembecky
Copy link
Contributor

rtrembecky commented Dec 13, 2024

I know there's #2 already with the similar error message, but that issue was also iterated on many times, and the cause is probably different.
For the record, I got to this state by:

Error:
Cannot read properties of null (reading 'program')

Stack:

      at BarrelFile.createSpecifiersMapping (../../node_modules/babel-plugin-transform-barrels/src/barrel.js:242:19)
      at BarrelFile.handleExportAllDeclaration (../../node_modules/babel-plugin-transform-barrels/src/barrel.js:214:25)
      at ../../node_modules/babel-plugin-transform-barrels/src/barrel.js:259:18
          at Array.every (<anonymous>)
      at BarrelFile.createSpecifiersMapping (../../node_modules/babel-plugin-transform-barrels/src/barrel.js:242:32)
      at BarrelFile.handleExportAllDeclaration (../../node_modules/babel-plugin-transform-barrels/src/barrel.js:214:25)
      at ../../node_modules/babel-plugin-transform-barrels/src/barrel.js:259:18
          at Array.every (<anonymous>)
      at BarrelFile.createSpecifiersMapping (../../node_modules/babel-plugin-transform-barrels/src/barrel.js:242:32)
      at BarrelFilesPackage.getBarrelFile (../../node_modules/babel-plugin-transform-barrels/src/barrel.js:325:24)
      at Function.getBarrelFile (../../node_modules/babel-plugin-transform-barrels/src/barrel.js:399:43)
      at importDeclarationVisitor (../../node_modules/babel-plugin-transform-barrels/src/main.js:22:46)
      at PluginPass.call (../../node_modules/babel-plugin-transform-barrels/src/main.js:93:7)

Investigation:

  • the last processed barrel file is libs/mobile/test-utils/src/index.ts, with content:
export * from './__mocks__/navigation';
export * from './testUtils';
  • the stacktrace is basically:
  • BarrelFilesPackage.getBarrelFile('/Users/richard/repos/xxx/libs/mobile/test-utils/src/index.ts')
  • barrelFile.createSpecifiersMapping()
BarrelFile.handleExportAllDeclaration(Node {
    type: 'ExportAllDeclaration',
    start: 40,
    end: 68,
    loc: SourceLocation {
      start: [Position],
      end: [Position],
      filename: undefined,
      identifierName: undefined
    },
    exportKind: 'value',
    source: Node {
      type: 'StringLiteral',
      start: 54,
      end: 67,
      loc: [SourceLocation],
      extra: [Object],
      value: './testUtils'
    },
    attributes: []
  })
  • in libs/mobile/test-utils/src/testUtils.tsx, there's this code:
// re-export everything
// eslint-disable-next-line no-restricted-imports
export * from '@testing-library/react-native';

// override render method
export { customRender as render, customRenderHook as renderHook };
  • next is exportedAllFile.createSpecifiersMapping(true) on the first import
BarrelFile.handleExportAllDeclaration(Node {
    type: 'ExportAllDeclaration',
    start: 3389,
    end: 3435,
    loc: SourceLocation {
      start: [Position],
      end: [Position],
      filename: undefined,
      identifierName: undefined
    },
    exportKind: 'value',
    source: Node {
      type: 'StringLiteral',
      start: 3403,
      end: 3434,
      loc: [SourceLocation],
      extra: [Object],
      value: '@testing-library/react-native'
    },
    attributes: [],
    trailingComments: [ [Object] ],
    leadingComments: [ [Object], [Object] ]
  })
  • I logged the resolved object:
ResolvedPath {
  originalPath: '/Users/richard/repos/grpn/mbnxt/node_modules/@testing-library/react-native',
  absEsmFile: '',
  absCjsFile: '/Users/richard/repos/grpn/mbnxt/node_modules/@testing-library/react-native/build/index.js',
  packageJsonExports: false
}
  • absoluteExportedPath is '', barrel is created for the empty path
  • exportedAllFile.createSpecifiersMapping(true)
  • const barrelAST = AST.filenameToAST('')
  • barrelAST is null
@FogelAI
Copy link
Owner

FogelAI commented Dec 25, 2024

Hi @rtrembecky

I have released a new version of the plugin (v1.0.23) that should resolve your issue.
Please update your version and let me know if it resolves your issue.

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