node --experimental-modules, requested module does not provide an export named

前端 未结 6 1944
孤街浪徒
孤街浪徒 2020-12-05 06:51

I\'ve installed Node 8.9.1 (same problem happens in v10.5.0).

I\'m trying to use named imports from npm packages in a file with the .mjs



        
6条回答
  •  鱼传尺愫
    2020-12-05 07:06

    I just had this error with nodejs express *.mjs file and --experimental-modules flag enabled for googleapis.

    import { google } from "googleapis";

    SyntaxError: The requested module 'googleapis' does not provide an export named 'google'

    Solution

    //not working!
    //import { google } from "googleapis";
    
    //working
    import googleapis from "googleapis";
    const { google } = googleapis;
    

    I do not understand why this is the case; if anyone knows why, please comment.

提交回复
热议问题